Capitalization Conventions

 

The guidelines in this chapter lay out a simple method for using case that, when applied consistently, make identifiers for types, members, and parameters easy to read.

To differentiate words in an identifier, capitalize the first letter of each word in the identifier. Do not use underscores to differentiate words, or for that matter, anywhere in identifiers. There are two appropriate ways to capitalize identifiers, depending on the use of the identifier:

  • PascalCasing

  • camelCasing

The PascalCasing convention, used for all identifiers except parameter names, capitalizes the first character of each word (including acronyms over two letters in length), as shown in the following examples:

PropertyDescriptor
HtmlTag

A special case is made for two-letter acronyms in which both letters are capitalized, as shown in the following identifier:

IOStream

The camelCasing convention, used only for parameter names, capitalizes the first character of each word except the first word, as shown in the following examples. As the example also shows, two-letter acronyms that begin a camel-cased identifier are both lowercase.

propertyDescriptor
ioStream
htmlTag

✓ DO use PascalCasing for all public member, type, and namespace names consisting of multiple words.

✓ DO use camelCasing for parameter names.

The following table describes the capitalization rules for different types of identifiers.

IdentifierCasingExample
NamespacePascalnamespace System.Security { ... }
TypePascalpublic class StreamReader { ... }
InterfacePascalpublic interface IEnumerable { ... }
MethodPascalpublic class Object { 
  public virtual string ToString(); 
 }
PropertyPascalpublic class String { 
  public int Length { get; } 
 }
EventPascalpublic class Process { 
  public event EventHandler Exited; 
 }
FieldPascalpublic class MessageQueue { 
  public static readonly TimeSpan 
 InfiniteTimeout; 
 } 
 public struct UInt32 { 
  public const Min = 0; 
 }
Enum valuePascalpublic enum FileMode { 
  Append, 
  ... 
 }
ParameterCamelpublic class Convert { 
  public static int ToInt32(string value); 
 }

Most compound terms are treated as single words for purposes of capitalization.

X 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 the purpose of casing guidelines, treat a closed-form compound word as a single word. Use a current dictionary to determine if a compound word is written in closed form.

PascalCamelNot
BitFlagbitFlagBitflag
CallbackcallbackCallBack
CanceledcanceledCancelled
DoNotdoNotDon't
EmailemailEMail
EndpointendpointEndPoint
FileNamefileNameFilename
GridlinegridlineGridLine
HashtablehashtableHashTable
IdidID
IndexesindexesIndices
LogOfflogOffLogOut
LogOnlogOnLogIn
MetadatametadataMetaData, metaData
MultipanelmultipanelMultiPanel
MultiviewmultiviewMultiView
NamespacenamespaceNameSpace
OkokOK
PipiPI
PlaceholderplaceholderPlaceHolder
SignInsignInSignOn
SignOutsignOutSignOff
UserNameuserNameUsername
WhiteSpacewhiteSpaceWhitespace
WritablewritableWriteable

Languages that can run on the CLR are not required to support case-sensitivity, although some do. Even if your language supports it, other languages that might access your framework do not. Any APIs that are externally accessible, therefore, cannot rely on case alone to distinguish between two names in the same context.

X DO NOT assume that all programming languages are case sensitive. They are not. Names cannot differ by case alone.

Portions © 2005, 2009 Microsoft Corporation. All rights reserved.

Reprinted by permission of Pearson Education, Inc. from Framework Design Guidelines: Conventions, Idioms, and Patterns for Reusable .NET Libraries, 2nd Edition by Krzysztof Cwalina and Brad Abrams, published Oct 22, 2008 by Addison-Wesley Professional as part of the Microsoft Windows Development Series.

Framework Design Guidelines
Naming Guidelines

Show: