C#声明变量也要遵循一定规则,使编码更规范。简单规则如下:
不能使用C#关键字,如class、int、bool等在C#有特殊意义的字符;
变量名通常不能有中文字符;
以字母或下划线开头,如age,_name等。
使用多个单词组成变量名时,使用骆驼命名法,即第一个单词的首字母小写,其他单词的首字母大写。
如:myName、showAge等。
@:为了实现与其它语言相通,在C#中不计入变量名称
int i; //合法 int No.1; //不合法 char use; //不合法,与关键字名称相同 char @use; //合法 float Main; //不合法,与函数名称相同
C#关键字完整列表 abstract as base bool break byte case catch char checked class const continue decimal default delegate do double else enum ecent explicit extern false finally fixed float for foreach get goto if implicit in int interface internal is lock long namespace new null object out override partial private protected public readonly ref return sbyte sealed set short sizeof stackalloc static struct switch this throw true try typeof uint ulong unchecked unsafe ushort using value virtual volatile volatile void where while yield