Click here to Skip to main content
13,052,351 members (49,079 online)
Click here to Skip to main content
Add your own
alternative version


46 bookmarked
Posted 7 Apr 2007

Coding Standards for C#: Names

, 7 Apr 2007
Rate this:
Please Sign up or sign in to vote.
Comprehensive and essential facts which we developers sometimes neglect in C#


When I was looking for a standard convention for generics, I came across a 50-page manual for coding standards for C#. I am sure that, apart from the author, there are few who actually go through and read all of them. So, I thought of coming up with this article. I have tried to comprehend the essential facts which we developers sometimes neglect in C#. I will also discuss some common pitfalls.

Small, sweet and simple.

That's how I describe it. I hope you enjoy reading.

Why Coding Standards

Simple: maintainability. If, 6 months down the line, your customer isn't too happy with the product and wants an enhancement in the application you have created, you should be able to do it without introducing new bugs. There are a lot of other good reasons, but this is the one which concerns us more than anything else.

Not following any standard is like going with a temporary solution (which might lead to a permanent problem) and, as you will see, it takes less effort to keep in mind a few simple measures than to do haphazard coding.

All you have to do is study good standards once and keep them in the back of your head. Trust me; it's worth it.


  1. Naming - What is meant by meaningful names
  2. Casing - When to use PascalCase and when camelCase
  3. Generics - Proper usage
  4. Delegates - Proper usage
  5. Miscellaneous - Some short tidbits
  6. Common Pitfalls - Mistakes we should watch out for
  7. References - Where to get more information


"The beginning of wisdom is to call things by their right names" - Chinese Proverb

"Meaningful" is the keyword in naming. By meaningful names, I mean concise names that accurately describe the variable, method or object. Let's see how this would be in C#:

Namespaces - Names should be meaningful and complete. Indicate your company or name, product and then your utility. Do not abbreviate.

namespace CompanyName.ProductName.Utility

namespace CN.PROD.UTIL

Classes - Class names should always be a noun and, again, should be meaningful. Avoid verbs.

class Image
class Filters

class Act
class Enhance

Methods - Always use a verb-noun pair, unless the method operates on its containing class, in which case, use just a verb.

public void InitializePath();
public void GetPath();
public void ShowChanges();
public void System.Windows.Forms.Form.Show();

public void Path();
public void Changes();

Methods with return values - The name should reflect the return value.

public int GetImageWidth(Bitmap image);

public int GetDimensions(Bitmap image);

Variables - Do not abbreviate variable names. Variable names should again be descriptive and meaningful.

int customerCount = 0;
int index = 0;
string temp = "";

int cc = 0;
int i = 0;
string t = "";

Private member variables - Prefix class member variables with m_.

public class Image
   private int m_initialWidth;
   private string m_filename;

Interfaces - Prefix all interface names with I. Use a name that reflects an interface's capabilities, either a general noun or an "-able".

interface IClock
   DateTime Time { get; set; }

interface IAlarmClock : IClock
   void Ring();
   DateTime AlarmTime { get; set; }

interface IDisposable
   void Dispose();

interface IEnumerable
   IEnumerator GetEnumerator();

Custom attributes - Suffix all attribute class names with Attribute. The C# compiler recognizes this and allows you to omit it when using it.

public class IsTestedAttribute : Attribute
   public override string ToString()
      return "Is Tested";

//"Attribute" suffix can be omitted
public void Ring();

Custom exceptions - Suffix all custom exception names with Exception.

public class UserNotExistentException :

Delegates - Suffix all event handlers with Handler; suffix everything else with Delegate.

public delegate void ImageChangedHandler();
public delegate string StringMethodDelegate();


C# standards dictate that you use a certain pattern of Pascal Casing (first word capitalized) and Camel Casing (all but first word capitalized).

Pascal Casing - Use PascalCasing for classes, types, methods and constants.

public class ImageClass
   const int MaxImageWidth = 100;
   public void ResizeImage();

enum Days

Camel Casing - Use camelCasing for local variables and method arguments.

int ResizeImage(int imageCount)
   for(int index = 0; index < imageCount; index++)


Generics, introduced in .NET 2.0, are classes that work uniformly on values of different types.

Use capital letters for types; don't use "Type" as a suffix.

public class Stack ‹T›

public class Stack ‹t›
public class Stack ‹Type›


Use delegate inference instead of explicit delegate instantiation.

public delegate void ImageChangedDelegate();
public void ChangeImage()

ImageChangedDelegate imageChanged = ChangeImage;

ImageChangedDelegate imageChanged =
    new ImageChangedDelegate(ChangeImage);

Use empty parenthesis on anonymous methods without parameters.

public delegate void ImageChangeDelegate();
ImageChangedDelegate imageChanged = delegate()


  • Avoid putting using statements inside a namespace
  • Check spelling in comments
  • Always start left curly brace { on a new line
  • Group framework namespaces together; add custom and thirdparty namespaces below
  • Use strict indentation (3 or 4 spaces, no tabs)
  • Avoid fully qualified type names
  • Indent comment at the same line as the code
  • All member variables should be declared at the top of classes; properties and methods should be separated by one line each
  • Declare local variables as close as possible to the first time they're used
  • File names should reflect the classes that they contain

Common Pitfalls

Let's face it, we all do these things one time or another. Let's avoid them as best as we can:

Names that make sense to no one but ourselves.

string myVar;

Single or double letter variable names (this is excusable for local variables).

int a, b, c, a1, j1, i, j, k, ii, jj, kk, etc.

Abstract names.

private void DoThis();
string ZimboVariable;



Different functions with similar names.


Names starting with underscores. They look cool, but let's not ;)

int _m1 = 0;
string __m2 = "";
string _TempVariable = "";

Variable names with subtle and context-less meanings.

string asterix = "";
// (this is the best function of all)
void God()


string num;
int abr;
int i;


And Thanks

For reading this far. I am looking forward to your valuable suggestions. Take care!


  • 7th April, 2007: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Web Developer
United States United States
Biography Whats that ?
lots to do so less time

You may also be interested in...


Comments and Discussions

GeneralMy vote of 5 Pin
AteşG26-Sep-11 2:13
memberAteşG26-Sep-11 2:13 
GeneralMy vote of 3 Pin
hfrmobile19-Jan-11 3:43
memberhfrmobile19-Jan-11 3:43 
QuestionAre there any standards to cover project structures? Pin
midspace11-Jan-10 17:15
membermidspace11-Jan-10 17:15 
AnswerRe: Are there any standards to cover project structures? Pin
hfrmobile19-Jan-11 3:49
memberhfrmobile19-Jan-11 3:49 
General.NET Design Guidelines for Class Library Developers Pin
james.e.welch9-Apr-07 11:54
memberjames.e.welch9-Apr-07 11:54 
GeneralRe: .NET Design Guidelines for Class Library Developers Pin
dnh16-Apr-07 5:39
memberdnh16-Apr-07 5:39 
GeneralLiked it Pin
Quartz.9-Apr-07 8:37
memberQuartz.9-Apr-07 8:37 
GeneralRe: Liked it Pin
DeepWaters11-Apr-07 11:09
memberDeepWaters11-Apr-07 11:09 
QuestionThis is okay? Pin
Syed M Hussain8-Apr-07 12:29
memberSyed M Hussain8-Apr-07 12:29 
AnswerRe: This is okay? Pin
inetfly1239-Apr-07 2:13
memberinetfly1239-Apr-07 2:13 
AnswerRe: This is okay? Pin
SDragon429-Apr-07 4:21
memberSDragon429-Apr-07 4:21 
AnswerRe: This is okay? Pin
DeepWaters11-Apr-07 11:08
memberDeepWaters11-Apr-07 11:08 
GeneralMethod parameters Pin
ComplexityChaos8-Apr-07 3:26
memberComplexityChaos8-Apr-07 3:26 
GeneralRe: Method parameters Pin
li_robert8-Apr-07 4:28
memberli_robert8-Apr-07 4:28 
GeneralRe: Method parameters Pin
SDragon429-Apr-07 4:10
memberSDragon429-Apr-07 4:10 
GeneralSome comments Pin
John C. Turner7-Apr-07 20:40
memberJohn C. Turner7-Apr-07 20:40 
GeneralRe: Some comments Pin
DeepWaters7-Apr-07 21:37
memberDeepWaters7-Apr-07 21:37 
QuestionReferencing class methods / variables Pin
Jamie Furtner7-Apr-07 20:22
memberJamie Furtner7-Apr-07 20:22 
AnswerRe: Referencing class methods / variables Pin
DeepWaters7-Apr-07 22:07
memberDeepWaters7-Apr-07 22:07 
AnswerRe: Referencing class methods / variables Pin
Kevmeister6817-Apr-07 19:15
memberKevmeister6817-Apr-07 19:15 
GeneralTwo more Rules Pin
Uwe Keim7-Apr-07 20:09
sitebuilderUwe Keim7-Apr-07 20:09 
GeneralRe: Two more Rules Pin
DeepWaters7-Apr-07 21:39
memberDeepWaters7-Apr-07 21:39 
GeneralChoose examples more carefuly Pin
dnh7-Apr-07 12:47
memberdnh7-Apr-07 12:47 
GeneralRe: Choose examples more carefuly Pin
DeepWaters7-Apr-07 13:13
memberDeepWaters7-Apr-07 13:13 
GeneralRe: Choose examples more carefuly Pin
dnh7-Apr-07 13:46
memberdnh7-Apr-07 13:46 
GeneralRe: Choose examples more carefuly Pin
DeepWaters7-Apr-07 22:50
memberDeepWaters7-Apr-07 22:50 
GeneralRe: Choose examples more carefuly Pin
dnh8-Apr-07 1:54
memberdnh8-Apr-07 1:54 
GeneralRe: Choose examples more carefuly Pin
DeepWaters8-Apr-07 9:27
memberDeepWaters8-Apr-07 9:27 
GeneralRe: Choose examples more carefuly Pin
dnh8-Apr-07 9:32
memberdnh8-Apr-07 9:32 
GeneralAdditional conventions Pin
SDragon427-Apr-07 12:45
memberSDragon427-Apr-07 12:45 
GeneralRe: Additional conventions Pin
DeepWaters7-Apr-07 18:03
memberDeepWaters7-Apr-07 18:03 
GeneralPrivate Member Variables Pin
SDragon427-Apr-07 12:38
memberSDragon427-Apr-07 12:38 
GeneralSo which one? Pin
inetfly1239-Apr-07 2:17
memberinetfly1239-Apr-07 2:17 
GeneralRe: So which one? Pin
SDragon429-Apr-07 3:55
memberSDragon429-Apr-07 3:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170713.1 | Last Updated 7 Apr 2007
Article Copyright 2007 by LakshmiChava
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid