Why is char '\ "' the same as char '"'?

quick question. Why are both lines below acceptable?

char x = '\"';
char y = '"';

If "is a special character, should the second line be marked as invalid?

+3
source share
2 answers

If "is a special character, should the second line be marked as invalid?

No, because language rules do not require that it be "executed in a character literal only inside a string literal.

This is consistent with the fact that this can be avoided anyway. Thus, there is one set of escape sequences that applies to both character and string literals, although \U........it will not succeed for any code point that is not represented by a single UTF-16 code module.

2.4.4.5 # ( ), - --:

, "(U + 0022),\(U + 005C)

2.4.4.4 ( ), :

, '(U + 0027),\(U + 005C)

, ' :

string x = "'";
string y = "\'";
Console.WriteLine(x == y); // Strings are equivalent
+14

, . Escape Sequence - : , udnerstanding. .

String s = """; //It would be unclear for the Compiler where the String ends and what is part of it. Hence Escape Sequencs are needed
char c = '"'; //It is clear where the Char starts and ends (the single Quotes). 
char c = '''; //again unclear what of those is the Char. Escape Sequence needed.
+3

All Articles