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

Ienumerator

hi i have a teachers class where i want the user to enter a few teachers and
iterate thru them.
In the main i get an error

System.Collections.IEnumerator' does not contain a definition for 'Length'
why is that?
is this approach right? I want to develop an OO App. so is this approach
right?

public class PermTeacher: IEnumerable
{
public ArrayList arrTeachers =null;
string name =null;
private IEnumerator e;
public PermTeacher()
{
}
public IEnumerator GetEnumerator()
{
throw new NotSupportedException();
}
public void addTeachers(string nm)
{
IEnumerator e;
PermTeacher p =new PermTeacher ();
p.name = nm;
arrTeachers = new ArrayList();
arrTeachers.Add (p);
//if (arrTeachers !=null)
e=this.arrTeachers.GetEnumerator();
}
public IEnumerator getTeachers()
{
return e;
}
}

static void Main()
{
Teachers.PermTeacher p = new Prac1.Teachers.PermTeacher();
p.addTeachers("teacher1");
IEnumerator en = p.getTeachers();
for (int i =0;i< en.Length ;i++) //Gives me an error here.
{
}
Application.Run(new Form1());
}
Nov 16 '05 #1
1 2099

"juan" <ch***@hotmail.com> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl...
hi i have a teachers class where i want the user to enter a few teachers
and
iterate thru them.
In the main i get an error

System.Collections.IEnumerator' does not contain a definition for 'Length'
why is that?
is this approach right? I want to develop an OO App. so is this approach
right?

public class PermTeacher: IEnumerable
{
public ArrayList arrTeachers =null;
string name =null;
private IEnumerator e;
public PermTeacher()
{
}
public IEnumerator GetEnumerator()
{
throw new NotSupportedException();
}
public void addTeachers(string nm)
{
IEnumerator e;
PermTeacher p =new PermTeacher ();
p.name = nm;
arrTeachers = new ArrayList();
arrTeachers.Add (p);
//if (arrTeachers !=null)
e=this.arrTeachers.GetEnumerator();
}
public IEnumerator getTeachers()
{
return e;
}
}

static void Main()
{
Teachers.PermTeacher p = new Prac1.Teachers.PermTeacher();
p.addTeachers("teacher1");
IEnumerator en = p.getTeachers();
for (int i =0;i< en.Length ;i++) //Gives me an error here.
{
}
Application.Run(new Form1());
}

IEnumerator is designed to iterate over a series of values without you
having to know anything about ordering or length(this isn't always ideal,
but it works much of the time). Its much more common to use the foreach
construct(Look it up on msdn) to access enumerators

If you want to write code yourself, you instead would use a while loop,
something like...

while (en.MoveNext()) {

//do your work here

}
(I think...havn't written one by hand in a long time, I could be making a
mistake)

Nov 16 '05 #2

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

Similar topics

9
by: Sasha | last post by:
Hi, I am extending standard IEnumerator, and I was just wondering what is the best way to make enumarator safe? What do I mean by safe? Detect deletes and all... My idea is to have private Guid...
1
by: juan | last post by:
hi i have a teachers class where i want the user to enter a few teachers and iterate thru them. In the main i get an error System.Collections.IEnumerator' does not contain a definition for...
3
by: Hans | last post by:
I implemented the IEnumerator interface in some classes to enable the use of the foreach statement. As you probalbly know, the interface asks for the implementation of object IEnumerator.Curren...
3
by: starter | last post by:
I am trying to learn IEnumerator and collections(ArrayList, Hashtable) in .NET. Can anyone tell me what is IEnumerator used for and any online resources would be helpful. Thanks
1
by: midnight madness | last post by:
I tried but failed to implement a template class that support IEnumerator<T> interface using C++/CLI in VS 2005 Professional version. I could not figure out the proper syntax to implement the...
11
by: Leslie Sanford | last post by:
I've been kicking around an idea mostly as a thought experiment at this point. The idea is to create a thread safe collection that implements the IEnumerable interface. The enumerators it creates...
5
by: Shikari Shambu | last post by:
Hi, I am trying to implement a collection that implements IEnumerable<T>. I keep getting the following error 'IEnumerator<...>.Current' in explicit interface declaration is not a member of...
3
by: EmilH | last post by:
Hi. I have read some examples of IEnumerator at http://www.codeproject.com/csharp/csenumerators.asp What if I have 2 arrays or collections, for example a DataSet which has 2 DataTables in my...
2
by: Henri.Chinasque | last post by:
I have a feeling this is a dumb one, but here it is: IEnumerator<Timplements IDisposable, but the thing is I'm not sure what I'm supposed to dispose! I'm also curious why IEnumerator<T>...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...

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.