Skip to main content

CODE NAMING CONVENTIONS

The bulk of the content below is reproduced from http://www.akadia.com/services/naming_conventions.html, written by Martin Zahn, Akadia AG, 20.03.2003 and have made some small changes, as time has gone by.

Naming Conventions for .NET / C# Projects

The original of this document was developed by the Microsoft special interest group. Martin Zahan made some add-ons and then by Warren Machanik, the abbreviation tables will change (and have changed from the original article, please email me it you have alternative suggestions or leave a comment) . These standards should be used I a step towards standardization of naming conventions that should be used with .NET projects. As to be used for all items when naming items. 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.

All examples are in the following

codeStyle

Capitalization Styles Defined

We define three types of capitalization styles:

Pascal case

The first letter in the identifier and the first letter of each subsequent concatenated word are capitalized.

BackColor, DataSet

Camel case

The first letter of an identifier is lowercase and the first letter of each subsequent concatenated word is capitalized.

numberOfDays, isValid

Uppercase

All letters in the identifier are capitalized.

ID, PI

Hungarian Type Notation Defined

Hungarian notation is any of a variety of standards for organizing a computer program by selecting a schema for naming your variables so that their type is readily available to someone familiar with the notation. It is in fact a commenting technique.

strFirstName, iNumberOfDays

In the .NET framework, there are a lot of types, so this has been extended and adapted, see tables below with these extensions

Naming Guidelines

1)    PRIVATE Variables (Fields in C#) Naming Guidelines

Naming guidelines

Prefix private variables with a "_" and Hungarian-style notation

Case guidelines

Use camel case as a general rule, or uppercase for very small words

_strFirstName, _dsetEmployees

// Field
private OleDbConnection _connection;

// Property
public OleDbConnection Connection
{
  get { return _connection; }
  set { _connection = value; }
}

2)    Local Variables Naming Guidelines

Naming guidelines

  • Prefix private or local variables with Hungarian-style notation.
  • See tables for prefixes

Case guidelines

Use camel case as a general rule, or uppercase for very small words

strFirstName, dsetEmployees

3)    Namespace Naming Guidelines

Naming guidelines

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.

Case guidelines

Use Pascal case as a general rule, or uppercase for very small words.

System.Windows.Forms, System.Web.UI

4)    Class Naming Guidelines

Naming guidelines

  • Use a noun or noun phrase to name a class.
  • Do not use a type prefix, such as C for class, on a class name.
  • Do not use the underscore character (_).

Case guidelines

Use Pascal case:

FileStream, Button

5)    Interface Naming Guidelines

Naming guidelines

  • Prefix interface names with the letter "I", to indicate that the type is an interface.
  • Do not use the underscore character (_).

Case guidelines

Use Pascal case:

IServiceProvider, IFormatable

6)    Parameter Naming Guidelines

Naming guidelines

  • 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 prefix parameter names with Hungarian type notation.
  • Do not use a prefix for parameter names of an event handler and exceptions.

Case guidelines

Use camel case:

pTypeName, pNumberOfItems

7)    Method Naming Guidelines

Naming guidelines

  • Use verbs or verb phrases to name methods.

Case guidelines

Use Pascal case. Example:

RemoveAll(), GetCharAt()

8)    Property / Enumerations Naming Guidelines

Naming guidelines

  • Use a noun or noun phrase to name properties.
  • Do not use Hungarian notation, so no prefix.

Case guidelines

Use Pascal case:

BackColor, NumberOfItems

9)    Event Naming Guidelines

Naming guidelines

Use an EventHandler suffix on event handler names.

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.

Name an event argument class with the EventArgs suffix.

Case guidelines

Use Pascal case. Example:

public delegate void MouseEventHandler(object sender, MouseEventArgs
e);

10)     Exception Naming Guidelines

Naming 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.

Case guidelines

Use Pascal case. Example:

catch (Exception ex)
{
  // Handle Exception
}

11)      Constant Naming Guidelines

Naming guidelines

The names of variables declared class constants should be all uppercase with words separated by underscores. It is recommended to use a grouping naming schema.

Case guidelines

Use uppercase Example (for group AP_WIN): AP_WIN_MIN_WIDTH, AP_WIN_MAX_WIDTH, AP_WIN_MIN_HIGHT, AP_WIN_MAX_HIGHT

12)    C# Primitive Type Notation

Sorted alphabetically across

bool

b

 

byte

y

 

char

c

 

decimal

dec

double

d

float

f

int

I

long

l

sbyte

sy

short

s

uint

ui

ulong

ul

ushort

us

      

13)    Visual Control Type Notation

I have left this is a straight table so that additions are easier

Control Type

Notation

Assembly

asm

Boolean

bln

Button

btn

Char

ch

CheckBox

cbx

ComboBox

cmb

Container

ctr

DataColumn

dcol

DataGrid

dgrid

DataGridDateTimePickerColumn

dgdtpc

DataGridTableStyle

dgts

DataGridTextBoxColumn

dgtbc

DataReader

dreader

DataRow

drow

DataSet

dset

DataTable

dtable

DateTime

date

Dialog

dialog

DialogResult

dr

Double

dbl

Exception

ex

GridView

gv

GroupBox

gbx

HashTable

htbl

ImageList

iml

Integer

int

Label

lbl

Literal

ltr

ListBox

lbx

ListView

lv

MarshallByRefObject

rmt

Mainmenu

mm

MenuItem

mi

MD5

md5

MDI-Frame

frame

MDI-Sheet

sheet

NumericUpDown

nud

Panel

pnl

PictureBox

pbx

RadioButton

rbtn

SDI-Form

form

SqlCommand

sqlcom

SqlCommandBuilder

sqlcomb

SqlConnection

sqlcon

SqlDataAdapter

sqlda

StatusBar

stb

String

str

StringBuilder

strb

TabControl

tabctrl

TabPage

tabpage

TextBox

tbx

ToolBar

tbr

ToolBarButton

tbb

Timer

tmr

UserControl

usr

WindowsPrincipal

wpl


 

This standard is best enjoyed with a cup of specialty coffee

Comments

Popular posts from this blog

SMTP servers of South Africa

SMTP Settings Below is a list of SMTP sites in South Africa, using this and the ISP Map you can try and find which one works best for you. Telkom smtp.saix.net (ADSL) smtp.telkomsa.co.za (56k dial up) smtp.telkomsa.net Internet Solutions smtp.isdsl.net (ADSL) smtp.dial-up.net (56k dial up on IS) smtp.layerone.net (3g backbone) Vodacom smtp.vodacom.co.za smtp.vodamail.co.za MTN smtp.mtn.co.za Cell C smtp.cellc.co.za (GPRS) mail.cmobile.co.za (also used by Virgin) ABSA mail.absa.co.za iBurst smtp.wbs.co.za smtp.iburst.co.za @lantic smtp.lantic.net (ADSL,Dialup, ISDN) Sentech smtp.sentech.co.za MWEB smtp.mweb.net (ADSL) - this is to be retired End June 2012, use below instead smtp.mweb.co.za (56k dial-up & ADSL & business) iAfrica smtp.uunet.co.za smtp.iafrica.com Neotel smtp.neotel.co.za Tiscali NOW MWeb smtp.tiscali.co.za Netactive NOW MWeb smtp.netactive.co.za Global smtp.global.co.za Hertzner Use y

Fixing winmail.dat problem - specifically in Quickbooks

For months we have had problems with attachments from Quickbooks. Having looked down many avenues I think we have found a fix or few: (See below for update) Here are a few websites that help out: Microsoft Outlook/Exchange MS-TNEF handling (aka "Winmail.dat", "Win.dat", or "Part 1.2" problem of unopenable email attachments) http://news.office-watch.com/t/n.aspx?a=716 KB958012 : When you use Outlook 2007 to send an e-mail message, the recipient of the message sees an attachment that is called Winmail.dat Essentially the summary is that there is a problem with Outlook trying to force Rich Text Format. so you need to turn that off. Mail users not receiving email in an Outlook derivative will have a problem. This format is called So: Go into Outlook On the "Tools" menu, click "Options", then click the "Mail Format" tab, and then the "Internet Format" button. Set "When sending Outlook Ri

Programmatically send email in Access using VBA and Outlook

When I first wrote my early Access system I used a function I setup in Outlook and then I called that. On upgrading I had a few problems with the older method then I found some help on the MSDN website here... and the related video. The first thing to do before starting the code is go into access, access the VBA (press Ctl+G) then click on "Tools" The "References" and then make sure you scroll down to "Microsoft Outlook ..." the version there will be determined by what version you have installed. This the code that I ended up with after looking at the site above Private olApp As Outlook.Application Private olNameSpace As Outlook.NameSpace ' The basics of this from MSDN site ' http://msdn.microsoft.com/en-us/library/ee208547(v=office.12).aspx Private Sub InitOutlook()  ' Initialize a session in Outlook   Set olApp = New Outlook.Application   'Return a reference to the MAPI layer   Set olNameSpace = olApp.GetNamespace("MA