C# Coding Standard - Naming Conventions and Style

 

Naming Conventions and Style

Use Pascal casing for type and method names and constants:

User camel casing for local variable names and method arguments:

void MyMethod(int someNumber)

{

       int number;

}

Prefix interface names with I

Interface IMyInterfance

{

       …

}

 

Prefix private member variables with m_. Use Pascal casing for the rest of a member variable name following the m_.

public class SomeClass

{

       private int m_Number;

}

Suffix customs attribute classes with Attribute.

public class TagColumnAttribute : Attribute

{

}

Suffix customs exception classes with Exception

public class CEWorkstationException:Exception

{

}

 

Name methods using web-object pair

Such as: ShowExamTrackingDialog();

Methods with return values should have a name describing the value returned.

Such as: GetRequestedReportState()

Use descriptive variable names.

a)         Avoid single character variable names

// void

int i;

int t;

// instead

int index;

int temp;

b)        Avoid using Hungarian notation for public or protected members

c)         Do not abbreviate words

// void

int num;

// instead

int number;

Always use C# predefined types rather than the aliases in the System namespace.

Use

Not Use

object obj;

Object obj;

string strConnection;

String strConnection;

int index;

Int32 index;

 

With generics, use capital letters for types. Reserve suffixing Type when dealing with the .NET type Type.

// Correct

public class LinkedList<K,T>

{

}

// Avoid

public class LinkedList<KeyType,DataType>

{

       …

}

Use meaningful namespace

CEWorkstation.Resource

Avoid fully qualified type names. Use the using statement instead.

using CEWorkstation.Resource

Avoid putting a using statement inside a namespace.

namespace CEWorksation.Resource

{

       using System;

       using System.Data;

       using System.Web;

}

转载于:https://www.cnblogs.com/wmz/archive/2008/02/01/CodeStandard.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值