【发布时间】:2011-01-20 15:30:22
【问题描述】:
如何公开List<T> 使其只读,但可以私下设置?
这不起作用:
public List<string> myList {readonly get; private set; }
即使你这样做:
public List<string> myList {get; private set; }
你仍然可以这样做:
myList.Add("TEST"); //This should not be allowed
我猜你可能有:
public List<string> myList {get{ return otherList;}}
private List<string> otherList {get;set;}
【问题讨论】: