This section will define the naming conventions that are generally accepted by the C# development community. Some companies may define naming conventions that differ from this, but that is done on an individual basis and is generally discouraged. Some of the objects discussed in this section may be beyond the reader's knowledge at this point, but this section can be referred back to later.
Much of the naming standards are derived from Microsoft's .NET Framework libraries. These standards have proven to make names readable and understandable "at a glance". By using the correct conventions when naming objects, you ensure that other C# programmers who read your code will easily understand what objects are without having to search your code for their definition.
Namespaces are named using Pascal Case (also called
UpperCamelCase) with no underscores. This means the first letter of every word in the name is capitalized. For example:
MyNewNamespace. Pascal Case also means that acronyms of three or more letters should only have the first letter capitalized (MyXmlNamespace instead of MyXMLNamespace).
If an assembly contains only one namespace, the assembly and the namespace should use the same name. Otherwise, assemblies should follow the normal Pascal Case format.
Classes and Structures edit
Pascal Case, no underscores or leading
I. Classes should not have the same name as the namespace in which they reside. Any acronyms of three or more letters should be Pascal Case, not all caps. Try to avoid abbreviations, and try to always use nouns.
Exception Classes edit
Follow class naming conventions, but add Exception to the end of the name. In .Net 2.0, all classes should inherit from the
System.Exception base class, and not inherit from the
Follow class naming conventions, but start the name with
I and capitalize the letter following the
I prefix helps to differentiate between Interfaces and classes and also to avoid name collisions.
Pascal Case, no underscores except in the event handlers. Try to avoid abbreviations. Many programmers have a nasty habit of overly abbreviating everything. This should be discouraged.
Properties and Public Member Variables edit
Pascal Case, no underscores. Try to avoid abbreviations.
Parameters and Procedure-level Variables edit
Camel Case (or
lowerCamelCase). Try to avoid abbreviations. Camel Case is the same as Pascal case, but the first letter of the first word is lowercased.
Class-level Private and Protected Variables edit
Camel Case with a leading underscore. Always indicate
private in the declaration. The leading underscore is the only controversial thing in this document. The leading character helps to prevent name collisions in constructors (a parameter and a private variable having the same name).
Controls on Forms edit
Pascal Case with a prefix that identifies it as being part of the UI instead of a purely coded control (example a temporary variable). Many developers use
ui as the prefix followed by a descriptive name such as
lblUserNickName ("txt" stands for TextBox control and "lbl" for Label control)
This is in effect Camel Case; furthermore, this naming convention is known as Hungarian naming convention and is typically discouraged in modern programming. Variables in this style have names like lblSurname or tbSurname, rather than surnameLabel or surnameTextBox. This has the added advantage that similar UI elements are listed alphabetically contiguously in IntelliSense.
Some samples are below for ASP.Net web form controls:
Pascal Case. The use of SCREAMING_CAPS is discouraged. This is a large change from earlier conventions. Most developers now realize that in using SCREAMING_CAPS they betray more implementation than is necessary. A large portion of the .NET Framework Design Guidelines is dedicated to this discussion.
Here is an example of a class that uses all of these naming conventions combined.
public class Customer : IDisposable
private string _customerName;
public string CustomerName
_customerName = value;
_lastUpdated = DateTime.Now;
private DateTime _lastUpdated;
public DateTime LastUpdated
_lastUpdated = value;
public void UpdateCustomer(string newName)
CustomerName = newName;
public void Dispose()