473,320 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Why IEnumerable<T> inherits from IEnumerable?

In .Net 2.0, Generics are introduced. I found that IEnumerable<T>
inherites from IEnumerable. This makes implementation of
IEnumerable<Thas to have two GetEnumerator methods defined( one for
IEnumerable<Tand the other for IEnumerable). I doubt why .Net class
hierarchy is designed in such a way. IMHO, they should not have
inheritance releationship, just like IList<Tand IList.

I googled the web and found two related articles.
http://www.wintellect.com/cs/blogs/p...numerable.aspx
http://blogs.msdn.com/brada/archive/...18/355755.aspx
But, the explanation is not satisfying.

Even though "IEnumerable<Tinherits from IEnumerable" seems follow
Liskov Substitution Principle, I believe, LSP is just a necessary
condition, not sufficent condition. And, If IEnumerable<Tdoesn't
inherit from IEnumerable, no old code would be broken.

Anybody can shed some light on that?

Mar 19 '07 #1
2 4568
On Mar 19, 8:53 am, "Morgan Cheng" <morgan.chen...@gmail.comwrote:

<snip>
Even though "IEnumerable<Tinherits from IEnumerable" seems follow
Liskov Substitution Principle, I believe, LSP is just a necessary
condition, not sufficent condition. And, If IEnumerable<Tdoesn't
inherit from IEnumerable, no old code would be broken.
But the old code wouldn't be as useful. Currently, if I have a method
which takes IEnumerable, and I have an object which implements
IEnumerable<T>, I can use the two together without any extra work. It
would have been possible to make a proxying class to convert from one
to the other, of course, but I don't think the pain involved is that
significant here.
Anybody can shed some light on that?
I thought the explanation from Anders as quoted by Brad was pretty
good, myself.

Jon

Mar 19 '07 #2
In my opinion, the inheritance decision comes from the interoperability (COM
interoperability, for example, because COM interop cannot access generics
directly, they can access the standard IEnumerable.
http://msdn2.microsoft.com/en-us/library/ms229590.aspx). And not all
languages have support for generics.
Also because an enumerable object is usually a compiler-generated enumerable
class so the double implementation is not much an issue.
I don't see anything exceptionally wrong with it.
"Morgan Cheng" <mo************@gmail.comha scritto nel messaggio
news:11**********************@l75g2000hse.googlegr oups.com...
In .Net 2.0, Generics are introduced. I found that IEnumerable<T>
inherites from IEnumerable. This makes implementation of
IEnumerable<Thas to have two GetEnumerator methods defined( one for
IEnumerable<Tand the other for IEnumerable). I doubt why .Net class
hierarchy is designed in such a way. IMHO, they should not have
inheritance releationship, just like IList<Tand IList.

I googled the web and found two related articles.
http://www.wintellect.com/cs/blogs/p...numerable.aspx
http://blogs.msdn.com/brada/archive/...18/355755.aspx
But, the explanation is not satisfying.

Even though "IEnumerable<Tinherits from IEnumerable" seems follow
Liskov Substitution Principle, I believe, LSP is just a necessary
condition, not sufficent condition. And, If IEnumerable<Tdoesn't
inherit from IEnumerable, no old code would be broken.

Anybody can shed some light on that?

Mar 19 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Doug Dew | last post by:
This won't compile: using IEnumerable<T> = System.Collections.Generic.IEnumerable<T>; namespace MyNamespace { public class MyClass<T> : IEnumerable<T> { // Appropriate stuff here }
10
by: jcc | last post by:
Hi guys, I'm a newbie to C#. My Visual Studio 2005 failed to compile the following code with error as 'HelloWorld.A' does not implement interface member...
15
by: Gustaf | last post by:
Using VS 2005. I got an 'IpForm' class and an 'IpFormCollection' class, containing IpForm objects. To iterate through IpFrom objects with foreach, the class is implemented as such: public class...
5
by: Shikari Shambu | last post by:
Hi, I am trying to implement a collection that implements IEnumerable<T>. I keep getting the following error 'IEnumerator<...>.Current' in explicit interface declaration is not a member of...
1
by: =?Utf-8?B?RnJhbmNvaXNWaWxqb2Vu?= | last post by:
Hi there, Does anybody know how to return the results of an IEnumerable<typeas an array of the same type i.e type in a web service call without first having to collect all elements in the...
2
by: Tony Johansson | last post by:
Hello! Below I have a working program. I have one generic class called Farm<T> with this header definition public class Farm<T: IEnumerable<Twhere T : Animal Now to my question I changed the...
0
by: Marc Gravell | last post by:
You could bypass the List<T>'s tendency to use ICollection<Tby simply not giving it an ICollection<T- for example, with the C# 3 extension method below you could use: List<Tlist = new...
1
by: shapper | last post by:
Hello, On my MVC projects I often create classes which contains properties which are lists of other classes. Should I start using IQueryable<Tor IEnumerable<Tinstead of List<T>? What are...
2
by: Berryl Hesh | last post by:
Converting in the other direction , IEnumerable<Interfaceto List<ImplInterface>, I can just create a new List<ImplInterface(data) where data is IEnumerable<Interface>. How can I convert the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.