dev*_*ull 4 .net c# constructor class-design
可能重复:
C#成员变量初始化; 最佳实践?
这是初始化类变量的正确方法.[1]和[2]之间有什么区别?
//[1]
public class Person
{
private int mPersonID = 0;
private string mPersonName = "";
}
Run Code Online (Sandbox Code Playgroud)
要么
//[2]
public class Person
{
private int mPersonID = 0;
private string mPersonName = "";
public Person()
{
InitializePerson();
}
private void InitializePerson()
{
mPersonID = 0;
mPersonName = "";
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
27213 次 |
最近记录: |