我有一个类如下:等效
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