411 REFERENCE · Wikibooks
C Sharp Programming/Keywords/foreach
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
Keywords foreach
__TOC__
The foreach keyword identifies a foreach loop.
// example of foreach to iterate over an array
public static void Main() {
int[] scores = new int [] { 54, 78, 34, 88, 98, 12 };
int total = 0;
foreach (int score in scores) {
total += score;
}
int averageScore = total/scores.Length;
}