可能重複:
C# member variable initialization; best practice?C#:初始化類變量
這是初始化類變量的正確方法。 [1]和[2]之間的區別是什麼?
//[1]
public class Person
{
private int mPersonID = 0;
private string mPersonName = "";
}
OR
//[2]
public class Person
{
private int mPersonID = 0;
private string mPersonName = "";
public Person()
{
InitializePerson();
}
private void InitializePerson()
{
mPersonID = 0;
mPersonName = "";
}
}
還有類似的問題在這裏:http://stackoverflow.com/questions/298183/c-member-variable-initialization-best-practice – RandomWebGuy 2011-06-09 03:21:23