How to iterate in 2d array when we have there employee info

  • Thread starter Thread starter Sudip_inn
  • Start date Start date
S

Sudip_inn

Guest
suppose i have 2d array and there i have employee info like id, name, salary, dob etc.

now how could i iterate array to extract each employee info and print it on screen using console.writeline?

share some code example.



// First
string[,] arr1 = {
{ "aa", "aaa" },
{ "bb", "bbb" }
};

// Second
string[][] arr2 = new[] {
new[] { "aa", "aaa" },
new[] { "bb", "bbb" }
};

// Iterate through first
for (int x = 0; x <= arr1.GetUpperBound(0); x++)
for (int y = 0; y <= arr1.GetUpperBound(1); y++)
Console.Write(arr1[x, y] + "; ");

Console.WriteLine(Environment.NewLine);

see above code.

what is difference between these two array declaration ? both the array is 2d array ?

string[,] arr1 = {
{ "aa", "aaa" },
{ "bb", "bbb" }
};

// Second
string[][] arr2 = new[] {
new[] { "aa", "aaa" },
new[] { "bb", "bbb" }
};

Continue reading...
 
Back
Top