473,320 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 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 5604
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Sherif ElMetainy | last post by:
Hello I was just got VS 2005 preview, and was trying generics. I tried the following code int intArray = new int; IList<int> intList = (IList<int>) intArray; it didn't compile, also the...
14
by: Jim | last post by:
I am using VB.Net 2.0 and I am completely new to the concept of implementing interfaces. Can anyone explain "implementing interfaces" to me and perhaps give me an example of implementing an...
2
by: Lucian Wischik | last post by:
Does ReadOnlyCollection<T> really implement IList<T>, like it claims to do? ... When I right-click on ReadOnlyCollection and look at its definition, it says this: public class...
2
by: Mahernoz | last post by:
Hi, I am c# coder, i want to know can i implement IList Interface in my WebForm? If yes, how? A short sweet example would be enough. thanks, mahernoz
6
by: Venkatesh Bhupathi | last post by:
Hi All, I am trying to inherit the Generic IList<Tinterface to form the typed collection of objects of type T. Following is my sample code, Public Class Record { public string name;...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.