Question

How do I declare backslash constant character in C#?

char Character_BACKSLASH = '\';

Thank you!

Rune

Was it helpful?

Solution

From Lexical structure

A character that follows a backslash character (\) in a character must be one of the following characters: ', ", \, 0, a, b, f, n, r, t, u, U, x, v. Otherwise, a compile-time error occurs.

So you just need to use;

char Character_BACKSLASH = '\\';

enter image description here

OTHER TIPS

char Character_BACKSLASH = '\\';

You need to escape your backslash literal:

const char BACKSLASH = '\\';

Or use the built-in value:

Path.DirectorySeparatorChar
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top