C# IEnumerable with Iterators -


I am trying to write an application that uses different types of archives (list, error, dictionary)

  1. Use the C #terterator (not FOREACH) Return

I created a class called students who have implemented the Inequable interface

I have 3 ways for each collection, and Each student returning a IEnunerable of

  public class Student: IEnumerable {// general list public IEnumerable getList) {List & lt; String & gt; List Students = New List & lt; String & gt; (); ListStudents.Add ("Bob"); ListStudents.Add ("Nancy"); For (int i = 0; i & lt; list students; count; i ++) {return list students [i]; }} // Generic Dictionary public IEnumerable getDiction () {dictionary & lt; String, string & gt; DictStudent = New Dictionary & lt; String, string & gt; (); DicStudents.Add ("First Name", "Nana"); For (int i = 0; i   public class getall: IEnumerable {public IEnumerator (GetEnumerator) {Student S = new student (); IEnumerator [] enumerator = new INMERATOR [3] (S.GetLeist (). GetEnumerator (), S.Get Dictation (). GetEnumerator (), s.getArray (). GetEnumerator (),}; return calculator [3];  

/ P>


OK, I request Misunderstood.

I have the following:

  Public class students: IEnumerable {int id; string name; string phone; public IEnumerable & lt; student & gt; ; GetStudentList () {list & lt; student & gt; e = new list & lt; student & gt; (); add e (new student () {name = "bob", id = 20, phone = "914 -123-1234 "}); Add new student () {name = "jack", id = 21, phone = "718-123-1234"}); Add e (new student () {name = "Nancy", id = 22, phone = "212-123-1234"}; for (int i = 0; i  

How do I return the list of students and write them in the console? I want to put my list of students in the student body and then iterate through those people and list the students Want to?

Is this possible?

OK, now your student class is really messed up as it Defined, each student has a list of students in it.

You will need three sections here:

  • Keep a student class - data members (who
  • a student class - who You probably want to apply ILISL (and possibly the list is taken from

  • )

    A programmable class, in which your main () method will be, , And will put the method responsible for putting the student object into the student's object.

In addition, Please note that a list is also an IEnumerable, so your code:

  list & lt; student & gt; e = new list & lt; student & gt; (); //// Blah-blah -BLA (int i = 0; i  

is exactly the same:

  list & lt; student & gt; e = new list & lt; student & gt; (); //// blah-blah-blah returns e;  

Comments