嗨下面的代碼的意圖是返回一個靜態類,其中包含一組相關的數據。你能推薦我怎樣才能做得更好?c#靜態類聲明
public class People
{
//want info to be setup in this class, so it can be accessed elsewhere
public static readonly string[] ab = { "ALBERT", "EINSTEIN"};
public static readonly string[] dk = { "DONALD", "KNUTH" };
//is this efficient or instantiated once per access? IF SO HOW CAN I DO THIS BETTER?
public static readonly Info AB = new Info(ab, 100);
public static readonly Info DK = new Info(dk, 80);
}
public class Info
{
private string[] _name;
private int _age;
public string[] Name { get{ return _name}; }
public int Age { get { return _age; } }
public Info(string[] n, int a)
{
_name = n;
_age = a;
}
}
fyi,值'Name'是可變的。 –