Home | Articles|Namespace|Interview Questions|Tools|Jobs|Projects|Community
Asp.net Tutorials

»Dotnet Ads
»Message Boards
Message Boards
Dotnet Books

»Member Details
Register
Login
LogOut
Submit Code
Submit Jobs
Submit Projects

»Competition
Community
Winners
Prizes
Write For Us
Members

»Other Resources
Links
Dotnet Resources

ASP.NET , C# coding standards

1.Indentation

When an expression will not fit a singe line break it up

Example:

longmethod(expr1 , expr2 , expr3 , expr4
expr5 , expr6 , expr7 , expr9)

breaking an arthimetic expression:
var = a*b +/ (c-g)-f +
c*b

2.Comments
Avoid Block comments where ever possible.
Use the c style comments
Example //comment block
Avoid comments that explain the obvious, code should be self explanatory good code with readable variable names and method names should not require comments

3.Declarations

One declarations per line is recommended as it encourages commenting

Example
Int I = 10; // initialize variable I with value 10
Int j = 20;

Avoid int I,j etc.

Try to initialize local variables as soon as they are declared

example

String name = myObject.name

Class and interface declarations

Avoid creating multiple classes in a single file.

4. Statements

if(condition)
{
//do something
}

Always use a curly brace scope in an if statement , even if conditions a single statement

Example

///avoid
If(I == 0)
//do something

///use
If(i==0)
{
//do something
}

//for statements
For ( I = 0; I < 10; I++)
{
}

//switch statements
Switch (condition)
{
Case A:
Break;
Case B:
Break;
default:
Break;
}


Naming Conventions

Class names should use the Pascal casing

Interface names should start with the I example IEnumerable

Text Fields should start with the prefic txt

Labels should start with the name lbl

List Boxes should start with the name lst

Drop Down List should start with the name dd


Use camel casing for local variables and methods arguments

Use descriptive variable name avoid such as I or t use index or temp instead

All member variables should be declared at the top

public class MyClass
{

Int m_number;
Int m_Name;

}

A file name should reflect the class it contains

Always place a curly brace ({) in a new line

Add CDATA tags to comments c

Have a Question and dont know the answer post it below and get answers in minutes

Due to spam this feature is disabled
To get answers fast , make sure you enter a detailed subject for example: "DataGrid issues need answer" not "DataGrid"

Subject:

Catjegory Name:

Message:



© 2008 dotnetwatch.com -- Privacy policy

Website Design & Internet Marketing by Shivam