0

I've read an article:

https://msdn.microsoft.com/en-us/library/92t2ye13(v=vs.110).aspx

They specify here that ICollection<T> derives from the two aforementioned interfaces. But why not simply inherit IEnumerable<T>? It already derives from the other (the IEnumerable one). So why do we inherit it once more? I don't understand...

Salah Akbari
  • 39,330
  • 10
  • 79
  • 109
A. Belyasova
  • 32
  • 2
  • 5
  • 2
    MSDN is documentation, not the source. – user4003407 Sep 30 '17 at 16:55
  • One possible reason could be that `ICollection` and `IEnumerable` existed long before `IEnumerable` appeared. It's always like that in application development - new things appear and you don't won't to break the existing code in any way... – Fabjan Sep 30 '17 at 17:14
  • No, I mean that we already have all the necessary behavior in 'IEnumerable' as it inherits 'IEnumerable'. If we erase 'IEnumerable' from the list of inherited by 'ICollection' interfaces, we, as far as I know, get the same result. So why being extra? – A. Belyasova Sep 30 '17 at 17:17
  • 2
    Just look at the source code, not MSDN: https://github.com/Microsoft/referencesource/blob/master/mscorlib/system/collections/generic/icollection.cs – Dennis Sep 30 '17 at 17:18
  • 1
    `IEnumerable` is listed on MSDN for exposition purposes, the source code, as mentioned above, doesn't list `IEnumerable` twice. – milleniumbug Sep 30 '17 at 17:24

1 Answers1

0

I believe it is more for backward compatibility with .NET1.0 when there was only IEnumerable. So a client which is still in older version will not be broken.

Dhejo
  • 71
  • 5