我有一個類如下:等效
public class Document
{
public List<DocumentSection> sections = new List<DocumentSection>();
...
各種問題涵蓋的情況,即財產必須寫在類內,但只讀從外面(http://stackoverflow.com/questions/4662180/c-sharp-public-variable-as-writeable-inside-the-clas-but-readonly-outside-the-cl)
我想做同樣的事情,但對於這個集合 - 允許從類中添加它,但只允許用戶在它外面迭代它。這是否優雅可行?
感謝
感謝Wiktor的,就像一個魅力! – Glinkot