C# Coding/Naming Guideline


Author: Chesta
 

Type

Naming Style

Naming

Example

 

Namespace

noun or noun phrase

Pascal

Microsoft.Office.PowerPoint.

Class

noun or noun phrase

Pascal

AppDomain

Interface

nouns or noun phrases, or adjectives that describe behavior

Pascal

ICustomAttributeProvider

Enumeration Type

Use a singular name for most Enum types, but use a plural name for Enum types that are bit fields.

Pascal

ErrorLevel

Enum values

Use a singular name for most Enum types, but use a plural name for Enum types that are bit fields.

Pascal

FatalError

Static public and
Static protected fields

Use nouns, noun phrases, or abbreviations of nouns to name static fields

Pascal

 

Read Only Static Field

Noun

Pascal

RedValue

Parameter

Use descriptive parameter names

Camel

string Format(string format, object[] args)

Method

Use verbs or verb phrases to name methods.

Pascal

RemoveAll()

Property

Use a noun or noun phrase to name properties.

Pascal

   public Color BackColor
   {
      // Code for Get and Set accessors goes here.
   }

Event

Use a gerund (the "ing" form of a verb) to create an event name

Pascal

ValueChanging

Protected Instant Field

Noun

Camel

redValue

Public Instant Value

Noun

Pascal

RedValue

Const Field

noun or noun phrase

Pascal

const int MaximumItems

Field

noun or noun phrase

Camel

listItem

Exception class

noun or noun phrase

Pascal

WebException

Generic Type

Do name generic type parameters with descriptive names, unless a single-letter name is completely self explanatory and a descriptive name would not add value.

Pascal

System.Collections.Generic.IDictionary<T Key, T Value>.

Resources

Do provide descriptive rather than short identifiers. Keep them concise

Pascal

Menus.FileMenu.Close.Color

Delegate

Delegates that are used to define an event handler for an event must be suffixed with EventHandler.

Pascal

public delegate CloseEventHandler(object sender, EventArgs arguments)

Camel:
In Camel casing only the first letter of the second, third, etc. word in a name is capitalized; for example,backColor

Pascal:
In Pascal casing the first letter of each word in an identifier is capitalized. For example, BackColor.



My Ideal guide is of Microsoft coding guideline, based on that I created one page notes. That could be pined on desk.

Following are the links of Naming guidelines in various framework, basic difference is for new namespace and classes. Pages contain language selector like VB and C#.

Dot net framework 1.1 naming guidelines (base guidelines)

http://msdn.microsoft.com/en-us/library/xzf533w0(VS.71).aspx

Dot net framework 4.0 naming guidelines

http://msdn.microsoft.com/en-us/library/ms229002(VS.100).aspx

Dot net framework 3.5 naming guidelines

http://msdn.microsoft.com/en-us/library/ms229002.aspx

Dot net framework 3.0 naming guidelines

http://msdn.microsoft.com/en-us/library/ms229002(VS.85).aspx

Dot net framework 2.0 naming guidelines

http://msdn.microsoft.com/en-us/library/ms229002(VS.80).aspx



The gadget spec URL could not be found

ĉ
Arun Agarwal,
Jun 15, 2010, 1:44 AM
Comments