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