May 262012
Programming in C#: c# static class declaration on newest questions tagged c# – Stack Overflow
Hi the intent of the code below is to return a static class which holds a related set of data. Can you recommend how I can do this better?
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;
}
}
See Answers
source: http://stackoverflow.com/questions/10762604/c-sharp-static-class-declaration
Programming in C#: programming-in-c
Recent Comments