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
*/
Posted Nov 29, 2007, 1:09 PM
Thank you, Alan
AlanPosted Nov 29, 2007, 12:46 PM
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.