473,704 Members | 2,781 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.GetEnumera tor();
}

but keep getting the error:

Error 1 'Foo' does not implement interface member
'System.Collect ions.Generic.IE numerable<strin g>.GetEnumerato r()'.
Foo.GetEnumerat or()' is either static, not public, or has the wrong
return type.

Any help would be appreciated.

Thanks,

Paul

Jan 9 '06 #1
1 5630
Paul <Ge**********@g mail.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.GetEnumera tor();
}

but keep getting the error:

Error 1 'Foo' does not implement interface member
'System.Collect ions.Generic.IE numerable<strin g>.GetEnumerato r()'.
Foo.GetEnumerat or()' 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<str ing> GetEnumerator()
{
return list.GetEnumera tor();
}

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

--
Jon Skeet - <sk***@pobox.co m>
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
2705
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 following didn't compile
14
1756
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 interface that would help me implement the IIneternetSecurityManager interface mentioned under "Creating a Customized URL Security Manager" on http://msdn.microsoft.com/library/default.asp?url=/workshop/security/szone/overview/overview.asp#SecurityZones...
2
4529
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 ReadOnlyCollection<T> : IList<T>,ICollection<T>,IEnumerable<T> ...
2
1264
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
4624
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; public string address;
0
8684
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9271
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9134
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8975
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6604
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5930
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4699
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3134
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2478
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.