These rules come from Microsoft's C# identifier naming rules and conventions, which follow the style of the .NET runtime team. The compiler doesn't enforce them, but code analysis rules can.
The naming table
| Identifier | Convention | Example |
|---|---|---|
| Classes, structs, records, enums, delegates | PascalCase | WorkerQueue |
| Interfaces | PascalCase with an I prefix | IWorkerQueue |
| Namespaces | PascalCase | Contoso.Billing |
| Methods, properties, events | PascalCase | StartEventProcessing() |
| Public fields | PascalCase | IsValid |
| Constants (all, including private) | PascalCase | MaxRetries |
| Parameters and local variables | camelCase | workerQueue |
| Private and internal fields | camelCase with _ | _workerQueue |
| Private and internal static fields | s_ prefix | s_workerQueue |
| Thread-static fields | t_ prefix | t_timeSpan |
| Generic type parameters | T, or descriptive with a T prefix | TSession |
| Attribute types | Attribute suffix | ObsoleteAttribute |
Constants are PascalCase, not ALL_CAPS
This catches people coming from Java, C or Python. Microsoft says to use PascalCase for constant names, both fields and local constants, including private and internal ones. Write const int MaxRetries = 3;, not MAX_RETRIES.
Records and primary constructors
Positional record parameters are PascalCase, because they become the record's public properties: record Person(string FirstName, string LastName);. Primary constructor parameters on ordinary classes and structs are camelCase, like any other parameter.
Other rules worth knowing
- Enums: use a singular noun for an ordinary enum and a plural noun for a
[Flags]enum. - Prefer clarity over brevity, and avoid single-letter names except for simple loop counters.
- Avoid abbreviations and acronyms unless they're widely known.
- Don't use two consecutive underscores in an identifier; those names are reserved for the compiler.
Microsoft's page doesn't give a rule for how to case a two-letter acronym, so check what your codebase or analyzer settings already do.
Converting names with Transform Case
Our snake_case, camelCase, PascalCase and CONSTANT_CASE converters treat an acronym as one word, so HTTP server error becomes HttpServerError and http_server_error. That matches Microsoft's examples for most names. Add the I, _, s_ or t_ prefix yourself where the table calls for one.
Naming conventions in other languages: Python, Java, Go (Golang), Rust, Kotlin, Swift, Dart, PHP. All side by side: 20 languages compared.
Sources
- C# identifier naming rules and conventions, Microsoft Learn
Questions
Should C# constants be ALL_CAPS?
No. Microsoft's conventions use PascalCase for all constants, including private and internal ones: MaxRetries.
How do you name private fields in C#?
camelCase with a leading underscore, such as _workerQueue. Private static fields use s_ and thread-static fields use t_.
Do C# interfaces start with I?
Yes. Interface names start with a capital I, as in IWorkerQueue.