c# 命名规范

C#代码书写规则:

1. 尽量使用接口,然后使用类实现接口,以提高程序的灵活性。

2.一行不要超过80个字符

3.尽量不要手动更改计算机生成的代码

4.关键的语句写注释

5.建议局部变量在最接近使用它的地方声明

6.不要使用goto系列语句,除非使用在跳出深层循环时

7.避免出现使用超过5个参数的方法。

8.避免书写代码量过大的try....catch模块

9.避免同一个文件中放置多个类

10.生成和构建一个长的字符串时,一定要使用StringBuilder类型,而不用string类型

11.switch语句一定要有default语句来处理意外情况

12.对于if语句,使用“{}”把语句块包含起来

13.尽量不使用this关键字引用

C#命名规范:

     1.用Pascal规则来命名方法和类型,pascal命名规则是第一个字母必须大写,并且后面的连接词第一个字母也要大写。

eg:public class DataGrid;

2.用camel规则来命名局部变量和方法的参数,名称中第一个单词首字母小写

eg:string strUserName

3.所有的成员变量前加前缀“_”

eg:Public class DataBase

{

private string _connectionString;

}

4.接口名称加前缀“I”

eg:public interface Iconvertible

{

byte ToByte();

}

   5.所有成员变量声明在类的顶端,用换行把他和其他方法分开

eg:private class Product

                       {

private string _productld;

private string _productName;

}

6.使用某个控件的值时,尽量命名局部变量

eg:public string GetTitle()

{

string title = lbl_Title.Text;

return title;

}

数据类型

 

数据类型简写

标准命名举例

Array

arr

arrShoppingList

Boolean                         bln blnIsPostBack
Byte                           byt bytPixelValue
Char                            chr chrDelimiter
DateTime                       dtm dtmStartDate
Decimal dec decAverageHeight
Double                           dbl dblSizeofUniverse
Integer         int intRowCounter
Long                             

lng

lngBillGatesIncome

Object           obj                  objReturnValue
Short shr shrAverage
Single sng sngMaximum
String

str

strFirstName
原文地址:https://www.cnblogs.com/KSalomo/p/6525751.html