Difference between IEnumerable and IEnumerable?

前端 未结 4 1247
[愿得一人]
[愿得一人] 2020-12-12 17:22

What is the difference between IEnumerable and IEnumerable?

I\'ve seen many framework classes implementing both these interfaces,

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-12 17:42

    As to why you see classes defining both, enough though IEnumerable< T > implements IEnumerable, its not needed but is is nice in a self documenting to list the sub interfaces at times. Consider

    interface IA { }
    interface IB : IA { }
    
    class A : IB {} // legal, IB implements IA
    
    class B : IA, IB {} // also legal, possible more clear on intent
    

提交回复
热议问题