IEnumerable.GetEnumerator() and IEnumerable<T>.GetEnumerator()

Posted by Dylan Lin on Stack Overflow See other posts from Stack Overflow or by Dylan Lin
Published on 2010-03-14T12:57:37Z Indexed on 2010/03/14 13:05 UTC
Read the original article Hit count: 617

Filed under:
|
|

Hi,

In the .net framework, there's a generic IEnumerable<T> interface which inherits from the not-generic IEnumerable, and they both have a GetEnumerator() method. The only differents between these two GetEnumerator() is the return type. Now I have a similar design, but when I compile the code, the compiler said:

MyInterface<T>.GetItem()' hides inherited member 'MyInterface.GetItem()'. Use the new keyword if hiding was intended.

The MyInterface<T>.GetItem() returns a concrete type T, while MyInterface.GetItem() returns type System.Object.

So I think if the BCL team guys compile the .net framework, they will get the same warning.

I think having compiler warnings is not good, what do you think? And how can I solve this problem? I mean I want to get the concrete type T when calling the MyInterface<T>.GetItem() not just a instance of type System.Object.

Thanks in advance! :-)

© Stack Overflow or respective owner

Related posts about ienumerable

Related posts about inheritance