foreach loop array c# code example
Example 1: c# loop through array
//iterate the array
for (int i = 0; i < arr.Length; i++)
{
// loop ...
}
// or
foreach (var element in arr)
{
// loop ...
}
Example 2: The foreach Loop c#
string[] names = {"William.", "James", "Oliver", "Lucas"};
foreach (string i in names)
{
Console.WriteLine(i);
}
Example 3: c# loop through array
for (int i = 0; i < theData.Length - 2; i+=3)
{
// use theData[i], theData[i+1], theData[i+2]
}