Collection -2D Array

2D 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

0 Comments

Featured Post

How to learn Azure without paid subscription

Microsoft Azure is a cloud service that is constantly expanding to help your organization meet business challenges. You can build, manage d...

Subscribe to the FREE Weekly Newsletter to receive all the latest Microsoft Azure, AI, Xamarin

Popular Posts