Pascal Case: B C D S
Pascal Case: B C D S
The original of this document was developed by the Microsoft special interest group. We made some addons.
This document explains the naming conventions that should be used with .NET projects.
A consistent naming pattern is one of the most important elements of predictability and discoverability
in a managed class library. Widespread use and understanding of these naming guidelines should
eliminate unclear code and make it easier for developers to understand shared code.
Pascal case
The first letter in the identifier and the first letter of each subsequent concatenated word are
capitalized.
Example:
BackColor, DataSet
Camel case
The first letter of an identifier is lowercase and the first letter of each subsequent concatenated word
is capitalized.
Example:
numberOfDays, isValid
Uppercase
Example:
ID, PI
Example:
strFirstName, iNumberOfDays
There are different opinions about using this kind of type notation in programming
nowadays. Some say that it’s useful, and it should be used everywhere to enhance clarity
of your code. Others say it just obfuscates your code, because it has no real advantage in
modern programming environments.
Our point of view is a moderated one: use it wisely, meaning, we only use Hungarian
notation for private or local variables, that are only accessible and interesting to the
programmer of the class.
Don’t use it with public variables, properties or parameters in methods, because they are
exposed to the outside world. Someone who uses your classes and accesses properties of
your class, is not interested in type, but just wants to use them.
In the .NET framework, there are a lot of types, so we extended and adapted the
Hungarian notation with our own type notation.
akadia.com/…/naming_conventions.html 1/5
4/15/2010 .NET Naming Conventions
Naming Guidelines
1). Private Variables (Fields in C#) Naming Guidelines
Naming guidelines
Case guidelines
Use camel case as a general rule, or uppercase for very small words
Example:
_strFirstName, _dsetEmployees
// Field
private OleDbConnection _connection;
// Property
public OleDbConnection Connection
{
get { return _connection; }
set { _connection = value; }
}
Case guidelines
Use camel case as a general rule, or uppercase for very small words
Example:
strFirstName, dsetEmployees
The general rule for naming namespaces is to use the company name followed by the
technology name and optionally the feature and design as follows:
CompanyName.TechnologyName[.Feature][.Design]
Prefixing namespace names with a company name or other well-established brand avoids
the possibility of two published namespaces having the same name. Use a stable,
recognized technology name at the second level of a hierarchical name.
Example:
Case guidelines
Use Pascal case as a general rule, or uppercase for very small words.
Example:
System.Windows.Forms, System.Web.UI
Case guidelines
FileStream, Button
Prefix interface names with the letter "I", to indicate that the type is an interface.
Do not use the underscore character (_).
Case guidelines
IServiceProvider, IFormatable
Use descriptive parameter names. Parameter names should be descriptive enough that the
name of the parameter and its type can be used to determine its meaning in most
scenarios. To distinguish parameters from other variables the prefix "p" should be used.
Do not use a prefix for parameter names of an event handler and exceptions.
Case guidelines
pTypeName, pNumberOfItems
Case guidelines
RemoveAll(), GetCharAt()
Case guidelines
BackColor, NumberOfItems
akadia.com/…/naming_conventions.html 3/5
4/15/2010 .NET Naming Conventions
Naming guidelines
Specify two parameters named sender and e. The sender parameter represents the object
that raised the event. The sender parameter is always of type object, even if it is possible
to use a more specific type. The state associated with the event is encapsulated in an
instance of an event class named "e". Use an appropriate and specific event class for the
e parameter type.
Case guidelines
Event handlers in Visual Studio .NET tend to use an "e" parameter for the event parameter to the call.
To ensure we avoid a conflict, we will use "ex" as a standard variable name for an Exception object.
Example
akadia.com/…/naming_conventions.html 5/5