2012.09.17.

Capitalization Conventions

Capitalization Conventions .NET Framework 4 Many of the naming conventions pertain to the casing of identifiers. It is important to note that the common language runtime (CLR) supports case-sensitive and case-insensitive languages. The capitalization conventions described in this topic make it easy for developers to understand and work with a library.

Casing Styles The following terms describe different ways to case identifiers. Pascal Casing The first letter in the identifier and the first letter of each subsequent concatenated word are capitalized. You can use Pascal case for identifiers of three or more characters. For example:

BackColor Camel Casing The first letter of an identifier is lowercase and the first letter of each subsequent concatenated word is capitalized. For example:

backColor Uppercase All letters in the identifier are capitalized. For example:

IO

Capitalization Rules for Identifiers When an identifier consists of multiple words, do not use separators, such as underscores ("_") or hyphens ("-"), between words. Instead, use casing to indicate the beginning of each word. The following guidelines provide the general rules for identifiers. Do use Pascal casing for all public member, type, and namespace names consisting of multiple words. Note that this rule does not apply to instance fields. For reasons that are detailed in the Member Design Guidelines1, you should not use public instance fields. Do use camel casing for parameter names. The following table summarizes the capitalization rules for identifiers and provides examples for the different types of identifiers.

Identifier

Case Example

Class

Pascal AppDomain

Enumeration type

Pascal ErrorLevel

msdn.microsoft.com/en-us/library/ms229043(d=printer,v=vs.100).aspx

1/6

2012.09.17.

Capitalization Conventions

Enumeration values

Pascal FatalError

Event

Pascal ValueChanged

Exception class

Pascal WebException

Read-only static field Pascal RedValue Interface

Pascal IDisposable

Method

Pascal ToString

Namespace

Pascal System.Drawing

Parameter

Camel typeName

Property

Pascal BackColor

Capitalization Rules for Acronyms An acronym is a word that is formed from the letters of words in a term or phrase. For example, HTML is an acronym for Hypertext Markup Language. You should include acronyms in identifiers only when they are widely known and well understood. Acronyms differ from abbreviations in that an abbreviation shortens a single word. For example, IDis an abbreviation for identifier. In general, library names should not use abbreviations. Note The two abbreviations that can be used in identifiers are IDand OK. In Pascal-cased identifiers they should appear as Id, and Ok. If used as the first word in a camel-cased identifier, they should appear as idand ok, respectively.

Casing of acronyms depends on the length of the acronym. All acronyms are at least two characters long. For the purposes of these guidelines, if an acronym is exactly two characters, it is considered a short acronym. An acronym of three or more characters is a long acronym. The following guidelines specify the proper casing for short and long acronyms. The identifier casing rules take precedence over acronym casing rules. Do capitalize both characters of two-character acronyms, except the first word of a camel-cased identifier. A property named DBRateis an example of a short acronym (DB) used as the first word of a Pascal-cased identifier. A parameter named ioChannelis an example of a short acronym (IO) used as the first word of a camel-cased identifier. Do capitalize only the first character of acronyms with three or more characters, except the first word of a camel-cased identifier. msdn.microsoft.com/en-us/library/ms229043(d=printer,v=vs.100).aspx

2/6

2012.09.17.

Capitalization Conventions

A class named XmlWriteris an example of a long acronym used as the first word of a Pascalcased identifier. A parameter named htmlReaderis an example of a long acronym used as the first word of a camel-cased identifier. Do not capitalize any of the characters of any acronyms, whatever their length, at the beginning of a camel-cased identifier. A parameter named xmlStreamis an example of a long acronym (xml) used as the first word of a camel-cased identifier. A parameter named dbServerNameis an example of a short acronym (db) used as the first word of a camel-cased identifier.

Capitalization Rules for Compound Words and Common Terms Do not capitalize each word in so-called closed-form compound words. These are compound words written as a single word, such as "endpoint". For example, hashtableis a closed-form compound word that should be treated as a single word and cased accordingly. In Pascal case, it is Hashtable; in camel case, it is hashtable. To determine whether a word is a closed-form compound word, check a current dictionary. The following list identifies some common terms that are not closed-form compound words. The word is shown in Pascal casing followed by the camel-cased form in parentheses.

BitFlag(bitFlag) FileName(fileName) LogOff(logOff) LogOn(logOn) SignIn(signIn) SignOut(signOut) UserName(userName) WhiteSpace(whiteSpace)

Case-Sensitivity The capitalization guidelines exist solely to make identifiers easier to read and recognize. Casing cannot be used as a means of avoiding name collisions between library elements. Do not assume that all programming languages are case-sensitive. They are not. Names cannot differ by case alone. Portions Copyright 2005 Microsoft Corporation. All rights reserved. Portions Copyright Addison-Wesley Corporation. All rights reserved. For more information on design guidelines, see the "Framework Design Guidelines: Conventions, Idioms, and Patterns for Reusable .NET Libraries" book by Krzysztof Cwalina and Brad Abrams, published by Addison-Wesley, 2005.

See Also Other Resources Design Guidelines for Developing Class Libraries2 msdn.microsoft.com/en-us/library/ms229043(d=printer,v=vs.100).aspx

3/6

2012.09.17.

Capitalization Conventions

Guidelines for Names3

Links Table 1http://msdn.microsoft.com/en-us/library/ms229059(v=vs.100).aspx 2http://msdn.microsoft.com/en-us/library/ms229042(v=vs.100).aspx 3http://msdn.microsoft.com/en-us/library/ms229002(v=vs.100).aspx

Community Content Using an underscore as a field prefix I'm not a big fan of underscores in fields. I tried it in 2003 for a couple of months, then woke up to the fact that it made my code harder to read. It's one of those religious topics though. 6/2/2012 Daniel Vaughan

6/2/2012 Daniel Vaughan

Acronyms and Abbreviations I don't have any issue with the conventions, but I'd just like to point out that I'm pretty sure your definitions for acronyms versus abbreviations is wrong. An acronym is a subset of abbreviation where the abbreviation is a pronounceable word,such as "NATO" or "NASA". Therefore "HTML" is not an acronym because we say "aytch tee em ell", not "hitemel" or something equally ridiculous. HTML and ID are initialisms, another subset of abbreviation. 3/14/2012 Sleepy Cat Chris

Camel case that parameter! I think that camel casing the parameter in a method or constructor makes it much more readable. The method name is Pascal cased, so having parameters inside that are camel cased makes it easier to separate the two categories of code. 2/27/2012 Anderson Mike

11/21/2011 Thundar Viking

Caps for properties - Argh! It really annoys me using capitals for property names. I find it difficult to tell something is a property or a class when scanning through code. 2/27/2012 Anderson Mike

10/15/2011 Mitzter

Agree with Blake I can understand the requirement for consistency, but Blake's argument is compelling. Otherwise you tend to end up reading things like Mr Doovdé in Fonejacker. msdn.microsoft.com/en-us/library/ms229043(d=printer,v=vs.100).aspx

4/6

2012.09.17.

Capitalization Conventions

1/4/2012 zippy72

Using an Underscore prefix for Variables I found a pretty standard convention on using the underscore as a prefix for a variable @ http://stackoverflow.com/questions/3136594/naming-convention-underscore-in-c-c-variables. The standrad seems to be when a private variable of a class is needed that represents a property of the class the prefix the private variable with the underscore:

private string _name; public string Name { get { return this._name; } set { this._name = value; } }

For C# using Auto-Implemented Properties (C# .3.0+ Programming Guide @ http://msdn.microsoft.com/en-us/library/bb384054.aspx) this should not be needed:

public string Name { get; set; } 12/7/2011 Themingware

ID or Id: Casing for Abbreviations Read Like Acronyms I hereby motion that the rules surrounding capitalization of abbreviations be changed for those abbreviations which are read in the same manner as acronyms. For example, when asking for my identification, and officer asks for my "I-D", not my "id". When I am referring to a database (which is one word, mind you), I refer to it as a "D-B", not a "dib" or a "dub". I speak these abbreviations in the same way that I would speak an acronym, by sounding out the individual letters (e.g., "I-O" for the acronym "IO"). My point is that if you read an abbreviation as you would an acronym with the same letters, the abbreviation should follow the same casing rules as the acronym.

With this in mind, down with "Id", "Ok", and "Db"! Long live "ID", "OK", and "DB"! (and before I get flamed for it, I realize that "DB" could be considered an acronym rather than an abbreviation for the closed compound word "database", but hopefully you still get the point)

msdn.microsoft.com/en-us/library/ms229043(d=printer,v=vs.100).aspx

5/6

2012.09.17.

Capitalization Conventions

9/23/2011 Blake D. _

Why the Recommendation to Capitalize Parameter Names Differently from Other Names? The guideline recommends Pascal casing for everything except parameter names. Why the exception for parameter names? 8/19/2011 ldskjflsdofjadslhasdifjasdhfkagshfonhaluenaiseufhi

© 2012 Microsoft. All rights reserved.

msdn.microsoft.com/en-us/library/ms229043(d=printer,v=vs.100).aspx

6/6