Home All Groups Group Topic Archive Search About
Author
25 Mar 2005 6:47 PM
dkocur
I'm trying to implement a custom collection, but I'm having trouble trying to
duplicate some of the "features" found in the generic collections. 
Specifically, implementing both the IEnumrable interface as well as the
IEnumerable<T> interface.  When I click on "Goto Definition" of List<T> it
shows that List<T> implements both interfaces, but HOW?

IEnumerable<T> specifies a method like:

T GetEnumerator();

IEnumerable specifies a method like:

Object GetEnumerator();

You can't implement both because the signatures only differ by return type. 
What trick am I missing?

Author
25 Mar 2005 7:21 PM
Lebesgue
microsoft.private.whidbey.csharp.ide || .language is the newsgroup you would
want to post to


Show quote
"dkocur" <dko***@discussions.microsoft.com> wrote in message
news:2A401EED-703B-4AE8-A20C-DEDDEB019B3B@microsoft.com...
> I'm trying to implement a custom collection, but I'm having trouble trying
to
> duplicate some of the "features" found in the generic collections.
> Specifically, implementing both the IEnumrable interface as well as the
> IEnumerable<T> interface.  When I click on "Goto Definition" of List<T> it
> shows that List<T> implements both interfaces, but HOW?
>
> IEnumerable<T> specifies a method like:
>
> T GetEnumerator();
>
> IEnumerable specifies a method like:
>
> Object GetEnumerator();
>
> You can't implement both because the signatures only differ by return
type.
> What trick am I missing?
Author
25 Mar 2005 7:30 PM
Mattias Sjögren
>You can't implement both because the signatures only differ by return type. 
>What trick am I missing?

Explicit implementation:

public IEnumerator<T> GetEnumerator() { ... }

IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator() }



Mattias

--
Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

AddThis Social Bookmark Button