Maha

Maha

  • NA
  • 0
  • 320.3k

NP63 How can decide value in the method

Nov 29 2007 10:18 AM

Hi Guys

 

NP63   How can decide value in the method

 

I got following program from the website.

http://www.c-sharpcorner.com/UploadFile/mahesh/WorkingWithArrays11142005060354AM/WorkingWithArrays.aspx

 

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 Main()

    {

        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

*/


Answers (2)