Practical Naming Standards for C#

A colleague of mine, Clint Edmondson, has collected a board set of useful coding standards for C# that can be found here

 

I am going to reproduce (e.g. copy) the set related to capitalization and naming in C# below.  I do encourage you to see the complete set of coding guidelines from Clint here though as he has gone a great job in documenting these.

 

5. Capitalization & Naming

5.1 Capitalization

Follow the standard Naming Guidelines set by the .NET framework team by using only three capitalization styles: Pascal, Camel, and Upper casing.

Examples:

Identifier Type

Capitalization Style

Example(s)

Abbreviations

Upper

ID, REF

Namespaces

Pascal

AppDomain, System.IO

Classes & Structs

Pascal

AppView

Constants & Enums

Pascal

TextStyles

Interfaces

Pascal

IEditableObject

Enum values

Pascal

TextStyles.BoldText

Property

Pascal

BackColor

Variables, and Attributes

Pascal (public)

Camel (private, protected, local)

WindowSize

windowWidth, windowHeight

Methods

Pascal (public, private, protected)

Camel (parameters)

ToString()

SetFilter(string filterValue)

Local Variables

Camel

recordCount

Guidelines:

o In Pascal casing, the first letter of an identifier is capitalized as well as the first letter of each concatenated word. This style is used for all public identifiers within a class library, including namespaces, classes and structures, properties, and methods.

o In Camel casing, the first letter of an identifier is lowercase but the first letter of each concatenated word is capitalized. This style is used for private and protected identifiers within the class library, parameters passed to methods, and local variables within a method.

o Upper casing is used only for abbreviated identifiers and acronyms of four letters or less.

5.2 Naming

Follow the standard set by the .NET framework team when it comes to naming. The Programming section of this document provides naming templates for each construct within the C# language. These templates can be used in conjunction with the tables provided in Appendix A. Naming Parts & Pairsto yield meaningful names in most scenarios.