radouane zili

radouane zili

  • NA
  • 7
  • 1.5k

how to get a field of an IEnumerator with an index

Sep 2 2016 7:18 AM
Hello,
 
Is there a way to get a property  of an object in an IEnumerator list with an index ?
 
Normally ,  if we have this structure :
 
Person[] peopleArray = new Person[3]
{
new Person("John", "Smith"),
new Person("Jim", "Johnson"),
new Person("Sue", "Rabon"),
};
 
People peopleList = new People(peopleArray);
 
the only way to access to the fileds is by using
 
foreach (Person p in peopleList)
Console.WriteLine(p.firstName+ " " + p.lastName);
}
 
so my question is :
 
how can we access to the field with  somtthing like this  
 
foreach (Person p in peopleList)
Console.WriteLine(p[0]  + " " + p[1]); ???
}
 
plz to help 
 
 
 

Answers (3)