I have the following code in a public static class:
public static class MyList
{
public static readonly SortedList<int, List<myObj>> CharList;
// ...etc.
}
.. but even using readonly
I can still add items to the list from another class:
MyList.CharList[100] = new List<myObj>() { new myObj(30, 30) };
or
MyList.CharList.Add(new List<myObj>() { new myObj(30, 30) });
Is there a way to make the thing read only without changing the implementation of CharList (it'll break some stuff)?
If I do have to change the implementation (to make it non-changeable), what would be the best way?
I need it to be List<T, T>, so ReadOnlyCollection won't do
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…