No nonsense simple and efficient coding standard C # 20100612
What to see their own code no problem, but a team, N number of individuals, N years of the code, it is more difficult to maintain, difficult to read, what kind of bad habits, wrong vulnerability can come out of it all out.
Chapter 1 program details Reference
※ error reference
messageReceiver.IsShow = Convert.ToInt32(dataRow["Is_Show"]) == 1 ? true : false;
1.1 specification defines
Do not write unnecessary recommended not much necessary to true : false .
Correct code reference
messageReceiver.IsShow = Convert.ToInt32(dataRow["Is_Show"]) == 1;
※ error reference
MessageAttachment result = null;
result = PackAttachment(table.Rows[0]);
return result;
1.2 specification defines
Unnecessary intermediate variables recommended to excessive avoided.
Correct code reference
return PackAttachment(table.Rows[0]);
※ error reference
DataSet GetApothecaryUnOnDateList( string code,string begin,string end);
1.3 specification defines
Must be separated by a space between the variable and variable spaces when the spaces, the spaces should not have deleted, it does not matter close together.
1.4 specification defines
As far as possible from the name of the variable, the variable type of restriction can know the details of variables, such as begin writing as beginDate.
Correct code reference
DataSet GetApothecaryUnOnDateList(string code, string beginDate, string endDate);
※ error reference
/// <summary>
/// pack
/// </summary>
public string pack
{
get { return _packE; }
set { _packE = value; }
}
1.5 specification defines
Property write a comment, otherwise who knows what this is it? .
1.6 specification defines
Properties To start with a capital letter, rare Microsoft program, begins with a lowercase attribute, the capital is not capitalized, it does not change the lowercase lowercase.
1.7 specification defines
If not necessary, try not to use _.
Correct code reference
/// <summary>
/// package name (English)
/// </summary>
public string pack
{
get { return packE; }
set { packE = value; }
}
※ error reference
/// <summary>
/// National Library of imported drug information entity
/// </summary>
[Serializable]
public class MediImportInfo
1.8 specification defines
Entity class, try to use * Entity class name, so we can easily know that this is the entity class? Control class? .
Correct code reference
/// <summary>
/// National Library of imported drug information entity
/// </summary>
[Serializable]
public class MediImportInfoEntity
Reproduced in: https: //my.oschina.net/iwenr/blog/227955