Why does ICollection implement both IEnumerable and IEnumerable

前端 未结 3 1903
深忆病人
深忆病人 2021-01-13 03:37

Why does ICollection implement both IEnumerable and IEnumerable?

What is the purpose of this? How does

3条回答
  •  梦毁少年i
    2021-01-13 04:07

    The non-generic interface is for backward compatibility. If you write code using generics and want to pass your collection to some module written in .NET 1.0 (which doesn't have generics) you still want this to succeed, and you want the old method to be able to iterate through it.

提交回复
热议问题