How'd they do that?

G

Guest

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?
 
L

Lebesgue

microsoft.private.whidbey.csharp.ide || .language is the newsgroup you would
want to post to
 
M

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top