You are on page 1of 55

C# , ASP.

Net Coding Standard


Coding Programmer

Professional


C# Language

Programming C# Language Coding Standard

Beginner
Syntax ..Logic

C# Language

English
.






..
Coding Standard

C# Coding Standard
Coding
Coding Coding

Coding
Programmer Logic


Software
Coding
App App
Program
Programming Code

Visual Basic Button Double Click




Tier OOP Rules
...Layer

App
Coding

Coding Standard

Coding
Standard Coding Standard


Coding
Coding Coding

Coding Coding
Rules


Programmer Programming Language

Language

Coding Standard



Tutorials

Good Code (Coding Standard)

.


.

.

Programmer App Performance


App

Standard Coding
. App

.Performance
.


.


.


ROI (Return On Investment) ,,,

.


.
.Performance
.

Programmer Coding



Maintain



Update Coding Standard


Standard Coding

Code Standard

Coding Standard

Coding Standard & Best Practices ? ? ? ? ? ? ? ? ? ? ? ?


Application Develop Coding
Standards Best Practices

Coding Standard Best Practices

. Microsoft
Guideline Developer
...

Programming



..

..

A


B


A

Naming Conventions & Standards

1.Pascal Casing
2.Camel Casing

Pascal Casing

Upper Case Lower Case


Camel Casing
Lower Case
Upper
Case

Pascal Casing
Eg. BackColor , ForeColor , GridView , TextBox , SqlDataSource

Camel Casing
Eg. backColor , foreColor , gridView , textBox , sqlDataSource

Class Name Method Name



Pascal Casing
Variable , Method Parameter Camel Casing

Public class PascalClass


{
//
{

Pascal Casing Class Name


Pascal Casing Method Name

Private void PascalMethod()


{
//
}

Camel Casing Variable

Private void PascalMethod(string name)


{
string name;
int salary;
string address;

// Camel Casing

Coding
Standard

Private void PascalMethod()


{
String nam;
String add;
Int sal;
}



Code

Variables


.Net Interface
Camel Casing ..(eg. IEntity)
Programmer Member Variables

string m_sName;
int nAge;

Programming Languages

.Net Programming Language
Member Variables

m_

.Net Coding Standard


C#.Net Variables
Camel Casing
Coding Standard

Local variables Underscore

Variable

int i;
int y;
int z;


.Net for looping
For looping

int i

For (int i , i <= 10 ; I ++)


Camel Casing for looping
Variables

Local Variable .Net Keyword

Boolean variables , Properties , method is keyword

Private boolean _IsFinished

File Name

Give File Name with Standard


Coding Standard
Class Name

Class Name HelloWorld File Name HelloWorld

Pascal Casing

Tab and Spacing with Standard


Text Indent
Space


Coding Standard
Text Indent Tab
Space Visual Studio Tab Space 4




Visual Studio IDE


Tab


Space 4

Comment with Standard


Comment
Comment







//Declared Variables
string name;
int age;
int phone;
Declared Variables Comment
Variables

Coding Standard


Comment
Code Same Level


//Declared Variables
string name;
int age;
int phone;



Code

//Comment Testing
String name = "Hello";
DateTime currentTime = DateTime.Now;
string fullMessage = "Hello " + name + " This Time is "+ currentTime.ToString();
Console.WriteLine(fullMessage);





Comment
Code Same Level
Coding Standard

Curly braces with Standard

Curly braces


Class Method


Private void PascalMethod(string name)


{
// Code
}



Visual Studio IDE
Auto

Private void PascalMethod(string name){


// Code
}

Line

if(.){ // Code

if()
{
// Code
}

if for Curly braces

Spacing using Standard


Operator
Space
Operator
. Space
IDE Support


if condition

if(Result==0)
{
for(int i=1;i<=10;i++)
{
// Code

}
}

Operator
Single Space Coding Standard

if ( Result == 0 )
{
for ( int i = 1 ; i <= 10 ; I++ )
{
//Code
}
}


Group Code
Blank Line

Blank Line Separate using Standard


Code Group

String name = "Hello";


DateTime currentTime = DateTime.Now;
string fullMessage = "Hello " + name + " This time is "+ currentTime.ToString();
Console.WriteLine(fullMessage);
Console.ReadLine();

Group Variables Group


fullMessage Group


Console Class Group
Console Console Group


Coding

Group


Code Group

String name = "Hello";


DateTime currentTime = DateTime.Now;
string fullMessage = "Hello " + name + " This Time is "+ currentTime.ToString();
Console.WriteLine(fullMessage);
Console.ReadLine();


. Coding Standard
Single Blank Line

Code Group
Code

#region & #endregion using Standard


Code Group

#region #endregion

namespace Console1
{
#region RegionTest
class Region
{
public static void Main()
{

Console.WriteLine("Hello Buddy ");


}
}
#endregion
}

Code
Code .Net Collapsed RegionTest

Field Method Property Standard

Declared Access Modifiers with Standard

1.Private Member Variables


2.Private Properties
3.Private Methods
4.Constructors
5.Public Properties
6.Public Methods


OOP Rules
OOP Rules Private AM Public AM
Coding Standard

UI (User Interface)
Standard

Give UI Name with Standard


UI Name


UI Element



() Variables
Identify

. UI Element

(ui_ )

UI Elements
Group
Group UI
Access

. UI Element
UI Element

Prefix

Table
Prefix

Control

Prefix

Label

lbl

TextBox

txt

DataGrid

dtg

Button

btn

ImageButton

imb

Hyperlink

hlk

DropDownList

ddl

ListBox

lst

DataList

dtl

Repeater

rep

Checkbox

chk

CheckBoxList

cbl

RadioButton

rdo

RadioButtonList

rbl

Image

img

Panel

pnl

PlaceHolder

phd

Table

tbl

Validators

val

ID Name Coding Standard


Naming



Program

Good Programming Practices


Good Programming Practices Program

1. Method Code
Method Coding Line 1~25

Method 25
Method

Private static void Main()


{
//Output 25
Output(name);
}

Private static void Output(string name)


{
Console.WriteLine(name);
}

Method Output
Method
Output

2.Method Name Method

Method Phone Number Save


Method Name Name
SavePhoneNumber

Private void SavePhoneNumber(int number)


{
// SavePhoneNumber Code
}




Method Code Phone No Save
Code

Method Name SavePhoneNumber

Method Name



Method Name

3. Method Coding Standard


Method Phone No Save

Phone No Save

Email Send Code
Email Send

string phonenumber;
string email;

SavePhoneNo(phonenumber);
SendEmail(email);

Private void SavePhoneNo(string no)

{
// Code that save PhoneNumber
}

Private void SendEmail(string mail)


{
// Code that send Email
}

Method


String phonenumber;
String email;

SaveNo(phonenumber,email);

Private void SaveNo(string no,string mail)


{
// Code that save PhoneNumber and Send Email

two functions in one method (thats wrong)


}

Method Coding Standard





Data Type

Declared DataType using Standard

4. Programmer



Data Type

int count;
int age;
string name;
object mytype;


Coding Standard
Int32 , String , Object

5.

Parameter

Code




Parameter
Parameter Code



User
(Character)


Error Error

Error Program



Program User

Coding Standard

Coding Standard

If ( MemberType == eMemberTypes.Registered )
{
// Code that do something for Registered Users
}

Else if ( MemberType == eMemberTypes.Guest )


{
// Code that do something for Guest Users
}

Else
{
// Error Throw and handling that Error
Error



User
Error


Error Handling try Block catch Block

Coding Standard


If ( MemberType == eMemberTypes.Registered )
{
// Code that do something for Registered Users
}

Else
{
// Code that do something for Guest users and Unkown users
Error Handle

User

Error


}

Error

Dont use Hardcode

6.Hardcode Constants
Constants File Code
Constants File Coding Standard


Pure Coding Standard Constants File
Configuration File Database
Code

Coding Standard





Code

7. HardCode String Resource Files


Configuration file , XML , Database

8. string Lower Case (or) Upper Case


Compare string Case Compare

If ( name.ToLower() == hello )
{
// Code
}

9. TextBox (Character)

txt.Text= ; string

Coding Standard

.Net string.Empty

If ( name == string.Empty )
{
// Code that do something
}

If ( name == )
{
// Code that do something
}

10. Member Variables Local


Variables
Member Variables Method

Error
Member Variables
Method Share Method

Track

11. enum
string (or) number
Gender Male Female
string .Net enum

HTML

enum Email
{
Html,
PlainText,
Attachment
}
void SendMail (string message, Email email)
{
switch ( email )
{
case Email.Html:
// Code that Do something
break;
case Email.PlainText:
// Code that Do something
break;
case Email.Attachment:
// Code that Do something
break;
default:
// Code that Do something
break;
}
}

Coding Standard

void SendMail (string message, string email)


{
switch ( email )
{
case "Html":
// Do something
break;
case "PlainText":
// Do something
break;
case "Attachment":
// Do something
break;
default:
// Do something
break;
}
}

12. Member Variables

public protected

OOP Rules Private


public Property

13. Event Handler method Required Action Code


Event Handler Method method

Method Method


14. Code Path



Hardcode

Drive Name
HardCode
Application Path Relative Path Programmatically

15. Code Hardcode


Drive D: Data Hardcode





D:
D:
A: , B: , Z:


Error

16. Application Run Application Run


Drive Location
Application


Code

Database

Code

Database Connetion


Code



Problem (Error)

User Message Box


Error
Message Box

Message Box
User


.. ()
User





Label

17.
Code Configuration File

Configuration File


Default Value Configuration

18. Configuration File


Label Error Throw


User
Sample

19. Error Message Error

User
Error in Application , There is an Error


User




Database Update Code
Error

Fail to Update Database

20.Login
Please make sure your
username and Password
. username and password are do not match

User

21. Error
Programming
Code Logic



Programming Code
Programmer

Program Programming Code


Error


Error
Message






..




..

.



Error Message


Coding Standard


22. Single File

Class

Coding Standard




23. File Coding




1000 Lines .. Class

24. public Method



public
Class
Same Assembly
internal private

25. Method Parameter Pass



Parameter .. Class () Structure
Define

26. Method Collection Return



null Return

Coding Standard

null return

Coding Standard Return null Return


Empty Collection
Return


ArrayList Return Method
Return


null Return (0)
Return


Application Calling


Count Check
null Return

Check

27. Copyright , Company Name , Description , Version Number


Information
Assembly Info File

28. File Folders

Hierarchies Level

ASP.Net


Folder
Coding Standard
Root Folder 10
Folders

Folders
Sub Folders 5



Coding Standard Hierarchies Level


Multiple Assembly



29. Code Database Connection


Sockets , FileStream .

Data Access Code try{} finally{}



Database
Connection





Error

Connection
finally Block

Private void GetData()


{
SqlConnection sqlcon=new SqlConnection();
..
..
..

try
{
sqlcon.Open();

Finally
{
sqlcon.Close();
}

Error Connection

30. Variables
Variables



Variables



string name;
int age;
int phone;



string name; int age; int phone;

31. loop string objects Manipulate


string
StringBuilder Class


string objects .Net



string


string object
string object




Sample

public string ComposeMessage (string[] lines)


{
string message = String.Empty;
for (int i = 0; i < lines.Length; i++)
{
message += lines [i];
}
return message;
}
string object message lines arrays loop

looping string object

recreation

loop

string object

loop string object
StringBuilder class

Looping string object
StringBuilder class Coding Standard


StringBuilder class

public string ComposeMessage (string[] lines)


{
StringBuilder message = new StringBuilder();
for (int i = 0; i < lines.Length; i++)
{
message.Append( lines[i] );
}
return message.ToString();
}
StringBuilder string object Coding
Standard
Looping

StringBuilder

StringBuilder string



Good Programming Practices

Coding Layer

... Architecture Coding Standard

Programmer




Architecture
Architecture

1. Layer


Multi Layer (n-Tier) Architecture
2. UI (User Interface) Database Access Code

ASP.Net SqlDataSource




Data Access Layer Database


Database


Update

3. Database Code
Database Exception

try catch finally Block Exception Handler
Database Exception Record
Record Command
Stored Procedure ConnectionString

Record Exception rethrown

Application Layer Exception catch



Action

4.
Independent Utility Classes Class Library

Database Class Library
Coding Standard
ASP.Net Coding Standard

Some of ASP.Net Coding Standards

1. Session Variables Code


Session Variables Class
Session Variables Stored
Access

Method
Session Class Access

Using System.Web.HttpContext.Current.Session;

Access
2. Session Object
Session Server Memory
User Server
Session Object

3. Page Look and Feel


Style Sheet (CSS)
Font-Names Font-Size UI Page(.aspx)
Skin File Page





Website


Website
.



CSS Skin File
Page



..
HTML Server Controls


Project HTML Server Controls


HTML Server Controls
ASP.Net Web Server Controls

Project

Comments
Comment


.. Comment

. Coding Comment
Variables Comment
. Comment HTML Comment

/* . */
// (or) ///


ASP.Net <%-- --%>

. Comment

Exception


Exception

1. Exception catch catch



Exception Code Exception

Exception

Developer Error

Programmatically Error Checking
Exception .

Message

Exception

2. Message

User
3. Exception Specific Exception
catch

catch(Exception)
{
Console.WriteLine("ERROR");
}





catch(FileIOException)
{
Console.WriteLine(IO Error);
}

.



Specific Exception


Exception


Exception Specific Exception

Exception




Coding Standard

. ..



Coding Standard











Program
Deadline Project Manager


..



Coding Line

Project




Program
Programmer


Program







.Boss
Coding Standard



C# Coding Standard

Zawminsoel

(Initial)

(MCTS , MCPD [Web])


(MCTS [MSSQL 2008])

You might also like