J
juan
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());
}
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());
}