C# loop through array code example
Example 1: c# loop through array
for (int i = 0; i < arr.Length; i++)
{
}
foreach (var element in arr)
{
}
Example 2: c# loop through array
int[] numberArray = { 4, 5, 6, 1, 2, 3, -2, -1, 0 };
foreach (int number in numberArray)
{
System.Console.Write("{0} ", number);
}
Example 3: c# loop string array
var strArr = new string[4] {"one", "Two", "Three", "Four"};
Console.WriteLine(strArr.Select((s, i) => $"Item no: {i + 1}, Value: {s}"));
Example 4: c# loop through array
for (int i = 0; i < theData.Length - 2; i+=3)
{
}