Why doesn't generic ICollection implement IReadOnlyCollection in .NET 4.5?

后端 未结 6 840
北恋
北恋 2020-12-03 02:45

In .NET 4.5 / C# 5, IReadOnlyCollection is declared with a Count property:

public interface IReadOnlyCollection

        
6条回答
  •  没有蜡笔的小新
    2020-12-03 02:52

    It would be semantically wrong, because obviously, not every ICollection is read-only.

    That said, they could have called the interface IReadableCollection, while an implementation could be called ReadOnlyCollection.

    However, they didn't go that route. Why? I saw a BCL team member write that they didn't want the collections API to become too convoluted. (Although it already is, frankly.)

提交回复
热议问题