Hi Guys
NP63 How can decide value in the method
I got following program from the website.
How can one decide in the following method parameter is 0 and 1.
int items1 = names.GetLength(0);
int items2 = names.GetLength(1);
Anyone knows please explain.
Thank you
using System;
public class GetValueSetValue
{
public static void
{
Array names = Array.CreateInstance(typeof(string), 2, 4);
names.SetValue("Rosy", 0, 0);
names.SetValue("Amy", 0, 1);
names.SetValue("Peter", 0, 2);
names.SetValue("Albert", 0, 3);
names.SetValue("Mel", 1, 0);
names.SetValue("Mongee", 1, 1);
names.SetValue("Luma", 1, 2);
names.SetValue("Lara", 1, 3);
int items1 = names.GetLength(0);
int items2 = names.GetLength(1);
for (int i = 0; i < items1; i++)
for (int j = 0; j < items2; j++)
Console.WriteLine(i.ToString() + "," + j.ToString() + ": " + names.GetValue(i, j));
}
}
/*
0,0: Rosy
0,1: Amy
0,2: Peter
0,3: Albert
1,0: Mel
1,1: Mongee
1,2: Luma
1,3: Lara
*/

AlanRank #669 · 3.6K reputationPosted Nov 29, 2007, 7:46 AM EST
Well names.GetLength(0) gets the length of the first dimension and names.GetLength(1) gets the length of the second dimension of the 'names' array.
You need to know this to iterate through the elements of the array.
Posted Nov 29, 2007, 8:09 AM EST
Thank you, Alan