C# identifier naming rules and conventions

An identifier is the name you assign to a type (class, interface, struct, record, delegate, or enum), member, variable, or namespace.

Naming rules

Valid identifiers must follow these rules:

  • Identifiers must start with a letter or underscore (_).
  • Identifiers may contain Unicode letter characters, decimal digit characters, Unicode connecting characters, Unicode combining characters, or Unicode formatting characters. For more information on Unicode categories, see the Unicode Category Database. You can declare identifiers that match C# keywords by using the @ prefix on the identifier. The @ is not part of the identifier name. For example, @if declares an identifier named if. These verbatim identifiers are primarily for interoperability with identifiers declared in other languages.

For a complete definition of valid identifiers, see the Identifiers topic in the C# Language Specification.

Naming conventions

In addition to the rules, there are many identifier naming conventions used throughout the .NET APIs. By convention, C# programs use PascalCase for type names, namespaces, and all public members. In addition, the following conventions are common:

  • Interface names start with a capital I.
  • Attribute types end with the word Attribute.
  • Enum types use a singular noun for non-flags, and a plural noun for flags.
  • Identifiers shouldn't contain two consecutive underscore (_) characters. Those names are reserved for compiler-generated identifiers.

For more information, see Naming conventions.

C# Language Specification

For more information, see the C# Language Specification. The language specification is the definitive source for C# syntax and usage.

See also