Difference between revisions of "Foreach"

From Logic Wiki
Jump to: navigation, search
m (Macrop moved page C Sharp foreach to Foreach without leaving a redirect)
 
m (1 revision imported)
 
(No difference)

Latest revision as of 14:27, 9 May 2016


Sample Usage

foreach iterates through array or IEnumerable / IEnumeralbe<T>

Array

Person[] people;
people = peopleRepo.GetPeople();
foreach (var person in people)
{
   PersonListBox.Items.Add(person);
}

IEnumerable

IEnumerable people;
people = peopleRepo.GetPeople();
foreach (var person in people)
{
   PersonListBox.Items.Add(person);
}