#19 – Contextual Keywords

There are some keywords in C# that are considered contextual, in that their usage is determined by their context.  Technically, you are free to use these keywords as identifiers, without needing the ‘@’ symbol.  But you should avoid doing this, since it could lead to confusion.

The contextual keywords are:  add, dynamic, get, global, partial, remove, set, value, var, where, yield

string var = "Don't do this, either";

#18 – What Is an Identifier?

An identifier is any name that you choose to use in a C# program for things like: variables, classes, interfaces, methods, properties, etc.

The rules for naming identifiers include:

  • They are case sensitive  (i.e. “name” is different from “Name”)
  • They must begin with a letter or underscore (‘_’)
  • They cannot include spaces
  • They can include Unicode characters
  • They cannot match any of the built-in C# keywords

You can actually name an identifier with a name matching a built-in keyword if you prefix the identifer with the ‘@’ symbol.  In the following example, we declare a variable of type string and name the variable “string”.  This is legal in C#, but not a good practice.

string @string = "Don't do this";