我有一个带有私有静态List<String>
集合的类。现在我想返回一个只读列表。这会是理想的方式吗?你会用另一种方式吗?这是正确的方法吗?
namespace Test
{
static class Storage
{
private static List<string> store;
static Storage()
{
store = new List<string>();
}
//Is it okay to have a getter in my static class to return my List Collection
public static System.Collections.ObjectModel.ReadOnlyCollection<string>getList
{
get
{
return stores.AsReadOnly();
}
}
public static void addString(string add)
{
store.Add(add);
}
}
}