Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Monday, June 13, 2011

Collection -2D Array

2 D Array
You want to use a 2D array containing any type(int,string ,etc) of value in your C# program
2D array contain 2 pair of values
Performance  PERF
2D Array  are slower to index elements than 1D arrays. They are sometimes more memory
2D Array String
String[,] os=new string[,]{
{"dev","Svalue"},
{"devenvexe","JValue"}
};
2D Array Int:
int[,] os=new int[,]{  {1,2}, {3,4} };
Get the Upperbound to Loop:
        

 string[,] ad = new string[,]
       {
           {"dev", "devenvexe"},
           {"TCS", "Tata"},
           {"CTS", "Cogn"},
          
       };

            // Get the upper bound to loop.
            //Upper bound means specify the dimention (0 or 1)
            for (int i = 0; i <= ad.GetUpperBound(0); i++)
            {
                string FDim = ad[i, 0]; // JS, TCS, CTS...
                string SDim = ad[i, 1]; // J Suqare, Tata, Cogn...

                MessageBox.Show(FDim);
                MessageBox.Show(SDim);
            }
If you want use Length keyword .it will return 6 so
string[,] ad = new string[,]
       {
           {"dev", "devenvexe"},
           {"TCS", "Tata"},
           {"CTS", "Cogn"},
          
       };

            // Get the upper bound to loop.
            //Upper bound means specify the dimention (0 or 1)
            for (int i = 0; i <= ad.Length/2; i++)
            {
                string FDim = ad[i, 0]; // JS, TCS, CTS...
                string SDim = ad[i, 1]; // J Suqare, Tata, Cogn...

                MessageBox.Show(FDim);
                MessageBox.Show(SDim);
            }
GetUpperBound VS Length:
Its faster to use Array Length
Looping Speed:
GetUpperBound: 142 ms
Length/2     : 47 ms

Post a Comment