foreach string in array c# code example
Example 1: loop through string array c#
string[] arr = new string[4];
arr[0] = "one";
arr[1] = "two";
arr[2] = "three";
arr[3] = "four";
foreach (string s in arr)
{
Console.WriteLine(s);
}
Example 2: 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 3: foreach array c#
int[,] numbers2D = new int[3, 2] { { 9, 99 }, { 3, 33 }, { 5, 55 } };
foreach (int i in numbers2D)
{
System.Console.Write("{0} ", i);
}
Example 4: foreach array c#
int[] numbers = { 4, 5, 6, 1, 2, 3, -2, -1, 0 };
foreach (int i in numbers)
{
System.Console.Write("{0} ", i);
}