#476 – Don’t Use Unicode Escape Sequences in Identifiers
December 15, 2011 Leave a comment
Although you can embed Unicode escape sequences within identifiers in a C# program, you shouldn’t. Including escape sequences makes the identifiers in the code less readable.
You can include Unicode characters for any Unicode character in the range of U+0000 to U+FFFF and the glyph will show up correctly in Visual Studio, if you have the proper fonts installed. You can also enter these characters directly using the appropriate international keyboard.
In the example below, we declare an identifier that includes the letter ‘c’ with a “cedilla”, using the Unicode value of U+00E7 for the cedilla.
string fa\u00E7ade = "Front of building";
This is valid C# code, but should be avoided. Instead, you can insert the glyph directly into the code:
string façade = "Front of building";
Visual Studio treats these as identical. We get a compiler warning if we include both definitions in a program.