471,350 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Beginner Implement IList problem

Hi all,

I'm trying to implement IList and keep getting an error when trying to
implement GetEnumerator().
My class has a List<String> and I've been using its methods as return
types for IList, but I can't seem to figure the the get enumerator
section. I try:

//IEnumerable
public IEnumerator GetEnumerator()
{

return list.GetEnumerator();
}

but keep getting the error:

Error 1 'Foo' does not implement interface member
'System.Collections.Generic.IEnumerable<string>.Ge tEnumerator()'.
Foo.GetEnumerator()' is either static, not public, or has the wrong
return type.

Any help would be appreciated.

Thanks,

Paul

Jan 9 '06 #1
1 5501
Paul <Ge**********@gmail.com> wrote:
I'm trying to implement IList and keep getting an error when trying to
implement GetEnumerator().
My class has a List<String> and I've been using its methods as return
types for IList, but I can't seem to figure the the get enumerator
section. I try:

//IEnumerable
public IEnumerator GetEnumerator()
{

return list.GetEnumerator();
}

but keep getting the error:

Error 1 'Foo' does not implement interface member
'System.Collections.Generic.IEnumerable<string>.Ge tEnumerator()'.
Foo.GetEnumerator()' is either static, not public, or has the wrong
return type.


Are you sure you're trying to implement IList rather than
IList<string>? The error message suggests that you're trying the latter
(which itself derives from IEnumerable<T>) whereas your method
declaration is really implementing IEnumerable (which you need if
you're implementing the non-generic IList). In fact, you'll need the
non-generic version anyway, because IEnumerable<T> extends IEnumerable.
You'll need to implement one of them explicitly, eg:

public IEnumerator<string> GetEnumerator()
{
return list.GetEnumerator();
}

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

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 9 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by Sherif ElMetainy | last post: by
2 posts views Thread by Lucian Wischik | last post: by
6 posts views Thread by Venkatesh Bhupathi | last post: by
reply views Thread by XIAOLAOHU | last post: by

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.