This document describes the coding standards for C# development. C# is a simplified form of C++, which has a Java like syntax. It is very easy to use compared to C++. All the memory management is taken care by .NET

1.1  General

1) All classes should be organized into right namespaces

2) Only use namespaces which are required for that particular class

3) No hard coding of literals, place them in a constants file or in a application config file

4) When coding in a multi-laered architecture, make sure the right objects are called within a layer. For ecample the data access objects should not be directly in the presentation layer

1.2  Class

1) A class should not be too big, not more than 400 – 500 lines

2) /// style comment is required at the top of the class describing what the class does

3) Class Name should be descriptive and should model the real world entities / the real domain objects

4) All form classes should end with ‘Form’; all data access Classes should end with ‘DAO’; all user control classes should end with ‘Control’; all value objects should end with ‘VO’

5) Use enum classes for groups of literals

6) Use the existing Microsoft .NET library classes, if one is available, do not create the same functionality in a custom class

1.3  Methods

1) Method names must be descriptive. Name of the method should begin with a verb. The name of the
method should be such that it describes what the method does.

2) The method should do only what it is designed for. It should not do anything extra

3) The method should not be too long. It should not have more 40 -60 lines of code.

4)  The Method names should begin with a Capital letter and every new word thereafter should begin
with a capital letter as well.

5) /// style comment is required for all methods at the beginning. Describe the input parameters,
return argument and a brief description for the methods

6) Do not repeat code, instead write a separate method and call them

7) Method names should not have special characters in them

8)  The search methods should begin with word ‘find’

9) The object load method should be named ‘retrieve’

10) There should be only one return statement and should be the last line of a method

1.4  Statements

1) The statements should not be too long, not more than 80 characters long. Wrap them into the next line,
if it goes beyond 80 characters

2) All important business logic should be commented

3) Do not use ‘==’ for checking object equality, use equals method

4) Create simple it-then-else conditions, don’t make them complicated and diffeclut to read

5) Make sure to have a finally block along with a try/catch block to handle any resource cleanup when
an exception is thrown

6) A try/catch block is not required if all the method does is rethrow the exception

7) Do null checks for all variables before using them

8) Use switch-case statements instead of multiple if-then-else blocks

9) Use the keyword ‘base’ to call super class methods. Especially when calling the method with the same
name to avoid stack over flow error

10) When instantiating Arraylists and Hastables, instantiate them with the initial capacity

1.5  Performance

1) Do not instantiate objects within a loop

2) Do not declare objects within a loop

3) If an object is required over a multiple method calls and over a long period, don’t create them every time, instead use caching to store as attribute in an object.

1.6  Variables

1) Variable names should be descriptive

2) Variable names should begin with a lowercase

3) The getter and setter methods should follow this style

private string attribute1;

public String Attribute1

{

get{ return attribute1; }

set{ attribute1= value; }

}

4) Variable names should not have special characters in them

5) Variables should not be made a member variable of a class just because it is being used repeatedly
in several methods. They should be made as member variable only if they are properties of its corresponding real world entity