//iterate the array
for (int i = 0; i < arr.Length; i++)
{
// loop ...
}
// or
foreach (var element in arr)
{
// loop ...
}
int[] numbers = new int[] {66,87,34,23,27,4};
foreach(int x in numbers){
Console.WriteLine(x);
}
string[] arr = new string[4]; // Initialize.
arr[0] = "one"; // Element 1.
arr[1] = "two"; // Element 2.
arr[2] = "three"; // Element 3.
arr[3] = "four"; // Element 4.
// Loop over strings.
foreach (string s in arr)
{
Console.WriteLine(s);
}
//Using Linq to itterate over an array
var strArr = new string[4] {"one", "Two", "Three", "Four"};
Console.WriteLine(strArr.Select((s, i) => $"Item no: {i + 1}, Value: {s}"));
for (int i = 0; i < theData.Length - 2; i+=3)
{
// use theData[i], theData[i+1], theData[i+2]
}