C# naming conventions
| What | Case | Example |
|---|---|---|
| Classes, records, structs, enums, delegates | PascalCase | OrderService |
| Interfaces | PascalCase with an I prefix | IOrderService |
| Methods, properties, events | PascalCase | GetTotal(), CreatedAt |
| Constants and enum members | PascalCase | MaxRetryCount |
| Parameters and local variables | camelCase | orderTotal |
| Private and internal fields | _camelCase | _orderTotal |
| Private static fields (runtime style) | s_camelCase | s_cache |
| Generic type parameters | PascalCase with a T prefix | TResult |
SCREAMING_SNAKE_CASE is not a .NET convention; C# constants are PascalCase. It is still common for values copied from C headers, environment variables and other languages, so the page offers it.
Acronyms follow their own rule: the .NET guidelines keep two-letter acronyms in capitals (IOStream, UIElement) and write longer ones like words (XmlReader, HttpClient). Id and Ok are abbreviations, not acronyms, so userID becomes UserId. In camelCase the first word is all lowercase (ioStream).
Valid identifiers need a little help sometimes: a name that starts with a digit gets a leading underscore (_2faEnabled), and a C# keyword gets the @ prefix (@class), which C# allows for exactly this.
The JSON naming policies are not converters
The System.Text.Json and Newtonsoft.Json cases on this page are what those libraries do to a property name, character for character. They were written for C# property names, so they give surprising results for other text:
JsonNamingPolicy.CamelCaseonly lowercases the capitals at the start:UserNamebecomesuserName,XMLHttpRequestbecomesxmlHttpRequest, butuser_namestaysuser_nameandSHA512HashbecomesshA512Hash. Newtonsoft'sCamelCaseNamingStrategydoes the same.JsonNamingPolicy.SnakeCaseLowerand the other separator policies (.NET 8 and later) split words at case changes and spaces, keep other characters as they are, and trim spaces at the ends.- Newtonsoft's
SnakeCaseNamingStrategysplits differently around digits and symbols:SHA512Hashissha512_hashin System.Text.Json andsh_a512_hashin Newtonsoft, andOrder#Idisorder#idagainstorder#_id. Switching libraries can rename JSON properties.
var options = new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower, // .NET 8+
};
string json = JsonSerializer.Serialize(new { OrderTotal = 42 }, options); // {"order_total":42}
Title Case in .NET
CultureInfo.InvariantCulture.TextInfo.ToTitleCase capitalizes each word and lowercases the rest, but leaves a word with no lowercase letters as it is, so acronyms survive: NASA launches becomes NASA Launches. A mixed-case word loses its inner capitals (iPhone becomes Iphone), and underscores and hyphens start a new word. The Title Case row above is that method's output.
FAQ
What is the difference between PascalCase and camelCase?
PascalCase capitalizes every word (OrderTotal); camelCase leaves the first word lowercase (orderTotal).
Does JsonNamingPolicy.CamelCase convert snake_case to camelCase?
No. It only lowercases the capital letters at the start of the name: UserName becomes userName, but user_name stays user_name and SHA512Hash becomes shA512Hash.
Do System.Text.Json and Newtonsoft.Json produce the same snake_case?
Mostly, but not always. SHA512Hash is sha512_hash with JsonNamingPolicy.SnakeCaseLower and sh_a512_hash with Newtonsoft's SnakeCaseNamingStrategy. The page shows both.
How do C# private fields get named?
The C# coding conventions use camelCase with a leading underscore for private and internal fields, for example _orderTotal.
Why is ToUpper on my Turkish text different?
The invariant culture does not map the Turkish dotted İ and dotless ı to other letters, while the Turkish culture does ("i".ToUpper(new CultureInfo("tr-TR")) is İ). This page uses the invariant culture, like ToUpperInvariant.
How do I convert a string to PascalCase in C#?
There is no built-in method. Split the text into words, capitalize the first letter of each with char.ToUpperInvariant, lowercase the rest and join them. On .NET 8 and later, JsonNamingPolicy.SnakeCaseLower.ConvertName is a quick way to find the word breaks.
Is my text uploaded?
No. The converter runs in your browser.