#476 – Don’t Use Unicode Escape Sequences in Identifiers

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.

Advertisement

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: