how to access jagged array by foreach in C#.net?
How can do this?
how to access jagged array by foreach in C#.net?
How can do this?
int[][] jaggedArray = new int[][]
{
new int[] { 0, 1, 2 },
new int[] { 3, 4 },
new int[] { 5 }
};
foreach (int[] array in jaggedArray)
{
foreach (int value in array)
{
Console.WriteLine(value.ToString());
}
}
Output:
0
1
2
3
4
5
You can use linq
foreach (int item in jaggedarray.SelectMany(i => i))
{
// work with item
}