473,386 Members | 2,114 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,386 software developers and data experts.

Generic Interface Implementation in C# Orcas Beta 1

In C# 2, this works just fine:

public class foo : IEnumerable<string>
{
private string[] _list;
public IEnumerator<stringGetEnumerator()
{
foreach (string s in _list)
yield return s;
}
}

However Orcas complains that:

'myNS.foo' does not implement interface member
'System.Collections.IEnumerable.GetEnumerator()'. 'myNS.foo.GetEnumerator()'
cannot implement 'System.Collections.IEnumerable.GetEnumerator()' because it
does not have the matching return type of 'System.Collections.IEnumerator'.

It appears that I'll have to add an explicit non-generic interface
implementation to appease the compiler:

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

Just wondering whether this is a change in generics implementation or just a
bug in beta 1.

Cheers,
Don

Jun 24 '07 #1
6 2789
"Donald Xie" <do********@msdn.nospamwrote in message
news:FA**********************************@microsof t.com...
In C# 2, this works just fine:

public class foo : IEnumerable<string>
{
private string[] _list;
public IEnumerator<stringGetEnumerator()
{
foreach (string s in _list)
yield return s;
}
}

However Orcas complains that:

'myNS.foo' does not implement interface member
'System.Collections.IEnumerable.GetEnumerator()'.
'myNS.foo.GetEnumerator()'
cannot implement 'System.Collections.IEnumerable.GetEnumerator()' because
it
does not have the matching return type of
'System.Collections.IEnumerator'.

It appears that I'll have to add an explicit non-generic interface
implementation to appease the compiler:

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

Just wondering whether this is a change in generics implementation or just
a
bug in beta 1.

Cheers,
Don
ive just done a simple binary sorted tree class,
and was confused by this error too,
I ended up inheriting only the non generic collection class stuff
System.Collections.CollectionBase

not sure what the pros and cons are ...

Colin =^.^=
Jun 24 '07 #2
Donald,

Nothing has changed, the same error comes up in C# 2.0, so it's not an
error in Orcas. This is what I get in C# 2.0:

Error 1 'foo' does not implement interface member
'System.Collections.IEnumerable.GetEnumerator()'. 'foo.GetEnumerator()' is
either static, not public, or has the wrong return type.
c:\temp\ConsoleApplication1\ConsoleApplication1\Pr ogram.cs 86 14
ConsoleApplication1

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Donald Xie" <do********@msdn.nospamwrote in message
news:FA**********************************@microsof t.com...
In C# 2, this works just fine:

public class foo : IEnumerable<string>
{
private string[] _list;
public IEnumerator<stringGetEnumerator()
{
foreach (string s in _list)
yield return s;
}
}

However Orcas complains that:

'myNS.foo' does not implement interface member
'System.Collections.IEnumerable.GetEnumerator()'.
'myNS.foo.GetEnumerator()'
cannot implement 'System.Collections.IEnumerable.GetEnumerator()' because
it
does not have the matching return type of
'System.Collections.IEnumerator'.

It appears that I'll have to add an explicit non-generic interface
implementation to appease the compiler:

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

Just wondering whether this is a change in generics implementation or just
a
bug in beta 1.

Cheers,
Don
Jun 24 '07 #3
Hmm, I was using VS2005 SP1, which seems to be happy with this. What version
are you using?

Thanks,
Don

"Nicholas Paldino [.NET/C# MVP]" wrote:
Donald,

Nothing has changed, the same error comes up in C# 2.0, so it's not an
error in Orcas. This is what I get in C# 2.0:

Error 1 'foo' does not implement interface member
'System.Collections.IEnumerable.GetEnumerator()'. 'foo.GetEnumerator()' is
either static, not public, or has the wrong return type.
c:\temp\ConsoleApplication1\ConsoleApplication1\Pr ogram.cs 86 14
ConsoleApplication1

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Donald Xie" <do********@msdn.nospamwrote in message
news:FA**********************************@microsof t.com...
In C# 2, this works just fine:

public class foo : IEnumerable<string>
{
private string[] _list;
public IEnumerator<stringGetEnumerator()
{
foreach (string s in _list)
yield return s;
}
}

However Orcas complains that:

'myNS.foo' does not implement interface member
'System.Collections.IEnumerable.GetEnumerator()'.
'myNS.foo.GetEnumerator()'
cannot implement 'System.Collections.IEnumerable.GetEnumerator()' because
it
does not have the matching return type of
'System.Collections.IEnumerator'.

It appears that I'll have to add an explicit non-generic interface
implementation to appease the compiler:

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

Just wondering whether this is a change in generics implementation or just
a
bug in beta 1.

Cheers,
Don
Jun 24 '07 #4
Donald Xie <do********@msdn.nospamwrote:
Hmm, I was using VS2005 SP1, which seems to be happy with this. What version
are you using?
I'm using VS2005 SP1 and get the same failure.

Complete code:

using System;
using System.Collections.Generic;

public class Test : IEnumerable<string>
{
private string[] _list;
public IEnumerator<stringGetEnumerator()
{
foreach (string s in _list)
yield return s;
}

static void Main()
{
}
}
Compilation (including compiler version number):

C:\Users\Jon\Test>csc Test.cs
Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.312
for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727
Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.

Test.cs(4,14): error CS0536: 'Test' does not implement interface member
'System.Collections.IEnumerable.GetEnumerator()'.
'Test.GetEnumerator()'
is either static, not public, or has the wrong return type.
c:\Windows\Microsoft.NET\Framework\v2.0.50727\msco rlib.dll: (Location
of symbol
related to previous error)
Test.cs(7,32): (Location of symbol related to previous error)

--
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
Jun 24 '07 #5
Thanks again Jon. Well I've just tried on my office PC with VS2..5 SP1, and I
get this error too!

I'll double check on my home PC when I get back tonight...

Cheers,
Don

"Jon Skeet [C# MVP]" wrote:
Donald Xie <do********@msdn.nospamwrote:
Hmm, I was using VS2005 SP1, which seems to be happy with this. What version
are you using?

I'm using VS2005 SP1 and get the same failure.

Complete code:

using System;
using System.Collections.Generic;

public class Test : IEnumerable<string>
{
private string[] _list;
public IEnumerator<stringGetEnumerator()
{
foreach (string s in _list)
yield return s;
}

static void Main()
{
}
}
Compilation (including compiler version number):

C:\Users\Jon\Test>csc Test.cs
Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.312
for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727
Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.

Test.cs(4,14): error CS0536: 'Test' does not implement interface member
'System.Collections.IEnumerable.GetEnumerator()'.
'Test.GetEnumerator()'
is either static, not public, or has the wrong return type.
c:\Windows\Microsoft.NET\Framework\v2.0.50727\msco rlib.dll: (Location
of symbol
related to previous error)
Test.cs(7,32): (Location of symbol related to previous error)

--
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
Jun 25 '07 #6
Excuse me when I'm pulling my foot from my mouth - the error is on my home PC
as well. Now I'm wondering what I was doing yesterday...

At least this is consistent so I just have to use the workaround.

Thanks for setting me straight Jon ;-)

Cheers,
Don

"Donald Xie" wrote:
Thanks again Jon. Well I've just tried on my office PC with VS2..5 SP1, and I
get this error too!

I'll double check on my home PC when I get back tonight...

Cheers,
Don

"Jon Skeet [C# MVP]" wrote:
Donald Xie <do********@msdn.nospamwrote:
Hmm, I was using VS2005 SP1, which seems to be happy with this. What version
are you using?
I'm using VS2005 SP1 and get the same failure.

Complete code:

using System;
using System.Collections.Generic;

public class Test : IEnumerable<string>
{
private string[] _list;
public IEnumerator<stringGetEnumerator()
{
foreach (string s in _list)
yield return s;
}

static void Main()
{
}
}
Compilation (including compiler version number):

C:\Users\Jon\Test>csc Test.cs
Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.312
for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727
Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.

Test.cs(4,14): error CS0536: 'Test' does not implement interface member
'System.Collections.IEnumerable.GetEnumerator()'.
'Test.GetEnumerator()'
is either static, not public, or has the wrong return type.
c:\Windows\Microsoft.NET\Framework\v2.0.50727\msco rlib.dll: (Location
of symbol
related to previous error)
Test.cs(7,32): (Location of symbol related to previous error)

--
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
Jun 25 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

49
by: Steven Bethard | last post by:
I promised I'd put together a PEP for a 'generic object' data type for Python 2.5 that allows one to replace __getitem__ style access with dotted-attribute style access (without declaring another...
3
by: SimonH | last post by:
Hi all, I would like to make a generic set of methods that could be called regardless of the database behind the scenes. One of the methods I would like would take a string sql statement and...
17
by: Andreas Huber | last post by:
What follows is a discussion of my experience with .NET generics & the ..NET framework (as implemented in the Visual Studio 2005 Beta 1), which leads to questions as to why certain things are the...
2
by: DeveloperX | last post by:
Hi, I've just downloaded the Orcas Express beta and it bombs on the first step (installing the 3.5 framework). It doesn't give me a specific error, it just calls home, tail between its legs :( ...
9
by: squishy | last post by:
So what new suprises are in store for us with Orcas? I am downloading the VPC now to try it out myself. But, I will go out on a very sturdy limb here and say that MS will try and get developers...
5
by: nhmark64 | last post by:
Hi, What is the relationship between "Microsoft .NET Framework 3.5 – Beta 1" and "Visual Studio Code Name "Orcas" Beta 1"? Should I install 1 first than the other, or just 1? I need to start...
13
by: rkausch | last post by:
Hello everyone, I'm writing because I'm frustrated with the implementation of C#'s generics, and need a workaround. I come from a Java background, and am currently writing a portion of an...
35
by: Jon Skeet [C# MVP] | last post by:
Just in case anyone else hadn't noticed (like me!), Visual Studio 2008 (Orcas) Beta 2 has shipped. The best starting point is probably Scott Guthrie's blog (which contains download links etc): ...
5
by: Showjump | last post by:
Just wondering how many of you all are using VS2008 bETA 2 to work on 2.0 projects? I dl'd the beta 2 release but have not installed ityet because i was concerned about future uninstall when the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
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...

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.