Why doesn't ICollection<T> implement ICollection?

This question already has an answer here:

  • Why does IEnumerable<T> inherit from IEnumerable? 4 answers

  • As Nick said, ICollection is pretty much useless.

    These interfaces are similar only by their name, CopyTo and Count are the only properties in common. Add , Remove , Clear , Contains and IsReadOnly have been added while IsSychronized and SyncRoot have been removed.

    In essence, ICollection<T> is mutable, ICollection is not.

    Krzysztof Cwalina has more on this topic

    ICollection<T> seems like ICollection , but it's actually a very different abstraction. We found that ICollection was not very useful. At the same time, we did not have an abstraction that represented an read/write non-indexed collection. ICollection<T> is such abstraction and you could say that ICollection does not have an exact corresponding peer in the generic world; IEnumerable<T> is the closest.


    ICollection<T> and ICollection are actually very different interfaces that unfortunately share a name and not much else.

    From http://blogs.msdn.com/b/kcwalina/archive/2005/09/23/collections.aspx

    ICollection<T> seems like ICollection , but it's actually a very different abstraction. We found that ICollection was not very useful. At the same time, we did not have an abstraction that represented an read/write non-indexed collection. ICollection<T> is such abstraction and you could say that ICollection does not have an exact corresponding peer in the generic world; IEnumerable<T> is the closest.


    First, IList<T> does not implement IList either, probably for the same reasons. IList<T> implements: ICollection<T>, IEnumerable<T>, IEnumerable

    Some parts of ICollection just aren't necessary, but changing an interface after it's out in the wild is breaking at best.

    Look at ICollection:

    public interface ICollection : IEnumerable
    {
        void CopyTo(Array array, int index);
    
        int Count { get; }
        bool IsSynchronized { get; }
        object SyncRoot { get; }
    }
    

    It's just not properties you need in most cases, when I want a Collection I've never once needed this, nor would want to implement it. It got old would be the reasoning I suppose, but you'd have to ask the .Net team for the affirmative answer.

    链接地址: http://www.djcxy.com/p/64332.html

    上一篇: SeekBar的拇指只有在触摸时才会出现

    下一篇: 为什么ICollection <T>没有实现ICollection?