There is no need to use escape output. for 'in c #?

On MSDN, I can read that \'this is an escape sequence for 'char. However, I can use it in a string without an escape sequence as follows:

Console.WriteLine("Press 'X' ");

How is this possible?

+5
source share
4 answers

But how could you write it like that char?

char c = '\'';
+7
source

char(literal of one character) is a different data type than string(verbose literal).

In C # a is chardeclared as:

var c = 'c';

whereas a is stringdeclared as:

var s = "asdf";

, (') , char, :

var c = '\''; 
+5

\'screening is required for char literals. The reason is that it 'can be interpreted as an alphabetic boundary symbol. For strings, this is pointless because there is nothing to confuse. In stringsturn \"makes sense.

+3
source

It says that you need to exit 'for a char data type.

char c = ''';  // compiler throws error
char c = '\''; // valid
0
source

All Articles