据我所知.NET4.0仍然缺少只读列表.为什么框架仍然缺少这种功能?这不是domain-driven design人最常见的功能之一吗?
One of the few advantages Java has over C# is this in the form of the Collections.unmodifiablelist(list) method, which it seems is long overdue in IList<T> or List<T>.
使用IEnumerable<T>
是问题的最简单解决方案,可以使用ToList
并返回一份副本.