473,382 Members | 1,424 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,382 software developers and data experts.

Q: returning wrong type from GetEnumerator?

I know this is simple problem but I am so new that there is some fundamental
disconnect in my understanding of: Enumerable, Enumerator, and Generics.

As a result I am having a problem debugging this error message
"Error 1 'SimpleSite.Email.Model.Hosts' does not implement interface member
'System.Collections.IEnumerable.GetEnumerator()'.
'SimpleSite.Email.Model.Hosts.GetEnumerator()' is either static, not public,
or has the wrong return type."

....in the following simple code...:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace SimpleSite.Email.Model
{
class Hosts : IEnumerable<Dictionary<String,Host>>
{
private Dictionary<String, Hosthosts;

Hosts()
{
hosts = new Dictionary<String, Host>();
}

public void Add(Host h)
{
if (hosts.Contains(h.getId()))
{
hosts.Remove(h.getId());
}
hosts.Add(h.getId(), h);
}
public IEnumerator<Dictionary<String,Host>GetEnumerator()
{
return (IEnumerator < Dictionary<String, Host)
this.hosts.GetEnumerator();
}
public Host Item(String key)
{
return hosts(key);
}
}
}

Any ideas why I am seeing this error and what I should change would be
greatly appreciated. Thanks!! - Richard

---------------
"Lisp doesn''t look any deader than usual to me."

- David Thornley, reply to a question older than most languages
Mar 1 '07 #1
3 3724
rchf <rc**@discussions.microsoft.comwrote:
I know this is simple problem but I am so new that there is some fundamental
disconnect in my understanding of: Enumerable, Enumerator, and Generics.

As a result I am having a problem debugging this error message
"Error 1 'SimpleSite.Email.Model.Hosts' does not implement interface member
'System.Collections.IEnumerable.GetEnumerator()'.
'SimpleSite.Email.Model.Hosts.GetEnumerator()' is either static, not public,
or has the wrong return type."

...in the following simple code...:
You're implementing System.Collections.Generic.IEnumerable<T>, but not
System.Collections.IEnumerable.

Just add:

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

and all should be well.

--
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
Mar 1 '07 #2
Thank you Jon - that did it! Seems one must specify the position in the
class hierarchy of the methods that are satisfying Interface specifications.
That was unexpected. Thanks again!
Mar 1 '07 #3
rchf <rc**@discussions.microsoft.comwrote:
Thank you Jon - that did it! Seems one must specify the position in the
class hierarchy of the methods that are satisfying Interface specifications.
That was unexpected. Thanks again!
No, it's not a case of specifying the position in the hierarchy. You
just need to implement one of the GetEnumerator methods explicitly
(i.e. including which interface you mean) because they both have the
same signature.

--
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
Mar 1 '07 #4

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

Similar topics

4
by: John C | last post by:
I'm new to C#, so just point me at the correct reference material if this question has been answered before. When creating a new class which implements the IDictionary interface, two versions of...
2
by: rajivpopat | last post by:
I've been reading a discussion thread at http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_frm/thread/119f8362a9f5ff52 regarding typecasting generic collections to...
6
by: Derrick | last post by:
Hello all; Since I do have working code, this is more for my curiosity only. I'm creating a "Plugin" architecture, following some of the many examples on the 'net. Basically what I have is...
2
by: Sam Marrocco | last post by:
I've constructed a class that inherits the NameObjectCollectionBase class. All works well, but I'd like to shadow the GetEnumerator method so that it returns an actual value *instead of a...
9
by: Paul | last post by:
Hi, I feel I'm going around circles on this one and would appreciate some other points of view. From a design / encapsulation point of view, what's the best practise for returning a private...
2
by: Paul | last post by:
I have two classes. One (FrontierApplication) is a definition of a record from a table. The other (FrontierApplicationCollection) is the collection of the first class. Below is how they are...
2
by: =?Utf-8?B?VGVk?= | last post by:
I have been asked to change an existing program which Implemented a Collection Class The current class had what is below (its just a summary of the code) Public Class FieldList Implements...
16
by: colin | last post by:
Hi, is it possible to have a recursive GetEnumerator for traversing a tree structure ? public IEnumerator<DTypeGetEnumerator() { return GetEnumerator(root);
2
by: Andrus | last post by:
I'm trying to compile myGeneration PropertyCollectionAll.cs file with VCS Express 2005 bot got error Error 1 The type or namespace name 'Collection' could not be found (are you missing a using...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.