0

Possible Duplicate:
Why does IEnumerable<T> inherit from IEnumerable?

Folks,

I started playing at implementing IEnumerable... actually it was an SOF "noob homework question" which got me started on this line. Yes, I AM that bored.

So I sit down to pop-out a quick SSCCE for an IEnumerable. Ask if you want to see my code, but it's not really pertinent to my question. Anyway, soon the cogs started turning (slowly, as my cogs are known to do) and... For the life of me, I can't imagine WHY implementing the IEnumerable<T> interface also forces you to expose the (non-generic) IEnumerable interface.

I've just been Googling for about half-an-hour, but haven't found anything which enlightens me as to why exposing the non-generic enumerator was made mandatory... when I actively DON'T WANT TO DO THAT, because I don't want non-generics code inveigling it's way into my codebase, and if it does I want it to fail.

The MS engineers are, IMHO, some of the best on the planet, so I know there MUST be a damn-good-reason (and quite possibly more than one) for this design decision.

So please can someone put me out of my misery and elighten me, please?

What I've found so far

Raymond Chen's recent series of blog posts ("The implementation of iterators in C# and its consequences") is a good place to get up to speed.

So I had quick squiz through "Part 1" and soon found my brain yielding null, and my finite state machine trying to backup my wazoo. I also quickly realised that I'm getting further and further off track.

What question should I be asking?

Yes, What's my question? Surely this MUST have been asked and answered (many times) before... but I can't find diddly. I guess I don't even know enough to ask the right question . Sooo... A google search term would do nicely.

Thank you all in advance for your time. I do appreciate it.

Cheers. Keith.

Community
  • 1
  • 1
corlettk
  • 13,288
  • 7
  • 38
  • 52
  • @Jon, yeah close it... that's (more or less) what I wanted to know, thanks... Except I am interested in the design thought BEHIND this decision... which is inherently subjective. – corlettk May 01 '11 at 09:11
  • One example of a generic function failing without `IEnumerable` would be `Cast()`. And before .net 4 `IEnumerable` didn't support generic variance. – CodesInChaos May 01 '11 at 09:16
  • Did you read the answers in the question I linked to, where the reasons behind it are explained? – Jon Skeet May 01 '11 at 11:55
  • Yeah, I read through all the answers in that thread, and followed links to the remainder of that blog discussion with Hejlsberg... there is quite I lot I don't don't agree with, probably because I don't understand it ;-) simply put: I don't think backwards compatability is ALLWAYS desirable; and Generics is one of those paradigm shifts which take time for everyone to get there heads around. I can't help wondering if Hejlsberg (a few years on) still thinks all generic collections would ideally inherit from there (inherently klunky) non-generic counterparts. – corlettk May 01 '11 at 12:20

1 Answers1

0

IEnumerable< T> implements IEnumerable, so it must define that...

Marino Šimić
  • 7,318
  • 1
  • 31
  • 61