Wanted: Help implementing IEnumerable


S

Siegfried Heintze

Can someone help me implement a singly linked list class as a exercise? I'm
getting the following syntax error:

Error 1 'SinglyLinkedListNode<T>.IEnumerable<...>.GetEnumerator()':
containing type does not implement interface
'System.Collections.Generic.IEnumerable<T>' F:\SinglyLinkedList.cs 17 24
InQLinkedList

I've been google searching and I have found others with this same error. In
fact, that is where I got these troublesome lines of code. But the solution
that works for them does not work for me!

What am I doing wrong?
Thanks,
Siegfried
P.S. Scrolll way down to find my version information.

Here is my attempt:
class SinglyLinkedListNode<T> //:IEnumerable<T>

{

public IEnumerator<T> GetEnumerator() { SinglyLinkedListNode<T> list = this;
while (list != null) { yield return list.data; list = list.next; } }

IEnumerator<T> IEnumerable<T>.GetEnumerator() { return GetEnumerator(); }

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

private T data;

private SinglyLinkedListNode<T> next;


public SinglyLinkedListNode(T data) { this.data = data; next = null; }

public SinglyLinkedListNode(T data, SinglyLinkedListNode<T> tail) {
this.data = data; next = tail; }

}



Microsoft Visual Studio 2008
Version 9.0.30729.1 SP
Microsoft .NET Framework
Version 3.5 SP1

Installed Edition: Standard

Microsoft Silverlight Projects 2008 91851-136-3759112-60601
Microsoft Silverlight Projects 2008
Version 9.0.30730.126

Microsoft Visual Basic 2008 91851-136-3759112-60601
Microsoft Visual Basic 2008

Microsoft Visual C# 2008 91851-136-3759112-60601
Microsoft Visual C# 2008

Microsoft Visual C++ 2008 91851-136-3759112-60601
Microsoft Visual C++ 2008

Microsoft Visual Web Developer 2008 91851-136-3759112-60601
Microsoft Visual Web Developer 2008

Hotfix for Microsoft Visual Studio 2008 Standard Edition - ENU (KB944899)
KB944899
This hotfix is for Microsoft Visual Studio 2008 Standard Edition - ENU.
If you later install a more recent service pack, this hotfix will be
uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/944899.

Hotfix for Microsoft Visual Studio 2008 Standard Edition - ENU (KB945282)
KB945282
This hotfix is for Microsoft Visual Studio 2008 Standard Edition - ENU.
If you later install a more recent service pack, this hotfix will be
uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/945282.

Hotfix for Microsoft Visual Studio 2008 Standard Edition - ENU (KB946040)
KB946040
This hotfix is for Microsoft Visual Studio 2008 Standard Edition - ENU.
If you later install a more recent service pack, this hotfix will be
uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/946040.

Hotfix for Microsoft Visual Studio 2008 Standard Edition - ENU (KB946308)
KB946308
This hotfix is for Microsoft Visual Studio 2008 Standard Edition - ENU.
If you later install a more recent service pack, this hotfix will be
uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/946308.

Hotfix for Microsoft Visual Studio 2008 Standard Edition - ENU (KB946344)
KB946344
This hotfix is for Microsoft Visual Studio 2008 Standard Edition - ENU.
If you later install a more recent service pack, this hotfix will be
uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/946344.

Hotfix for Microsoft Visual Studio 2008 Standard Edition - ENU (KB946581)
KB946581
This hotfix is for Microsoft Visual Studio 2008 Standard Edition - ENU.
If you later install a more recent service pack, this hotfix will be
uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/946581.

Hotfix for Microsoft Visual Studio 2008 Standard Edition - ENU (KB947173)
KB947173
This hotfix is for Microsoft Visual Studio 2008 Standard Edition - ENU.
If you later install a more recent service pack, this hotfix will be
uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/947173.

Hotfix for Microsoft Visual Studio 2008 Standard Edition - ENU (KB947540)
KB947540
This hotfix is for Microsoft Visual Studio 2008 Standard Edition - ENU.
If you later install a more recent service pack, this hotfix will be
uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/947540.

Hotfix for Microsoft Visual Studio 2008 Standard Edition - ENU (KB947789)
KB947789
This hotfix is for Microsoft Visual Studio 2008 Standard Edition - ENU.
If you later install a more recent service pack, this hotfix will be
uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/947789.

Hotfix for Microsoft Visual Studio 2008 Standard Edition - ENU (KB948127)
KB948127
This hotfix is for Microsoft Visual Studio 2008 Standard Edition - ENU.
If you later install a more recent service pack, this hotfix will be
uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/948127.

Hotfix for Microsoft Visual Studio 2008 Standard Edition - ENU (KB953256)
KB953256
This hotfix is for Microsoft Visual Studio 2008 Standard Edition - ENU.
If you later install a more recent service pack, this hotfix will be
uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/953256.

Hotfix for Microsoft Visual Studio 2008 Standard Edition - ENU (KB971092)
KB971092
This hotfix is for Microsoft Visual Studio 2008 Standard Edition - ENU.
If you later install a more recent service pack, this hotfix will be
uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/971092.

Microsoft Visual Studio 2008 Standard Edition - ENU Service Pack 1
(KB945140) KB945140
This service pack is for Microsoft Visual Studio 2008 Standard Edition -
ENU.
If you later install a more recent service pack, this service pack will be
uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/945140.

Microsoft Visual Studio 2008 Standard Edition - ENU Service Pack 1
(KB947888) KB947888
This service pack is for Microsoft Visual Studio 2008 Standard Edition -
ENU.
If you later install a more recent service pack, this service pack will be
uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/947888.

Microsoft Visual Studio 2008 Standard Edition - ENU Service Pack 1
(KB948484) KB948484
This service pack is for Microsoft Visual Studio 2008 Standard Edition -
ENU.
If you later install a more recent service pack, this service pack will be
uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/948484.

Security Update for Microsoft Visual Studio 2008 Standard Edition - ENU
(KB972222) KB972222
This security update is for Microsoft Visual Studio 2008 Standard Edition -
ENU.
If you later install a more recent service pack, this security update will
be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/972222.

Update for Microsoft Visual Studio 2008 Standard Edition - ENU (KB956453)
KB956453
This update is for Microsoft Visual Studio 2008 Standard Edition - ENU.
If you later install a more recent service pack, this update will be
uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/956453.

Update for Microsoft Visual Studio 2008 Standard Edition - ENU (KB967143)
KB967143
This update is for Microsoft Visual Studio 2008 Standard Edition - ENU.
If you later install a more recent service pack, this update will be
uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/967143.
 
Ad

Advertisements

P

Peter Duniho

Siegfried said:
Can someone help me implement a singly linked list class as a exercise? I'm
getting the following syntax error:

Error 1 'SinglyLinkedListNode<T>.IEnumerable<...>.GetEnumerator()':
containing type does not implement interface
'System.Collections.Generic.IEnumerable<T>' F:\SinglyLinkedList.cs 17 24
InQLinkedList

I've been google searching and I have found others with this same error. In
fact, that is where I got these troublesome lines of code. But the solution
that works for them does not work for me!

What am I doing wrong?

I would say that the most obvious problem is that you have implemented
"IEnumerator<T> GetEnumerator()" twice, and "IEnumerator
GetEnumerator()" not at all.

The question sounds suspiciously like a homework assignment, and really
if so you should just ask your teacher. But not having actually tested
this by trying to compile your code, I believe that if you simply change
your second GetEnumerator() method to be declared as "IEnumerator
IEnumerable.GetEnumerator()", it will work.

Pete
 
S

Siegfried Heintze

No, this is an exercise I made up for myself. I'm an IT professional that
has been doing java for while.

When I use your suggestion, I get this error:

Error 1 Using the generic type 'System.Collections.Generic.IEnumerator<T>'
requires '1' type arguments SinglyLinkedList.cs 20 9 LinkedList

Incidently, this example does not compile for me either. I get the same
errors as above (which is why I included the version info).

http://msdn.microsoft.com/en-us/library/ee5kxzk0(VS.80).aspx

thanks,
Siegfried
 
Ad

Advertisements

P

Peter Duniho

Siegfried said:
[...]
When I use your suggestion, I get this error:

Error 1 Using the generic type 'System.Collections.Generic.IEnumerator<T>'
requires '1' type arguments SinglyLinkedList.cs 20 9 LinkedList

Sounds like you are missing a fully-qualified type name or "using"
directive. The compiler thinks when you write "IEnumerator" you're
referring to the generic type.

Either change the type name so that it's fully qualified —
"System.Collections.IEnumerator" — or add a "using System.Collections;"
to the file.
Incidently, this example does not compile for me either. I get the same
errors as above (which is why I included the version info).

http://msdn.microsoft.com/en-us/library/ee5kxzk0(VS.80).aspx

The example should compile fine if you copy it verbatim. It has the
necessary "using" directives.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top