假设我有这个:
public class MyClass
{
private readonly List<string> _strings = new List<string>();
public IEnumerable<string> MyStrings
{
get
{
return _strings;
}
}
}
如何防止以下内容实际添加到字符串的成员变量列表中?
var theClass = new MyClass();
((List<string>)theClass.MyStrings).Add("I do not want to be able to add this!");