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

Understanding about Azure Region, Geographies, Availability Zones and Region Pairs

Introduction Microsoft Azure services are available in 53 regions around the world, with plans announced for 7 additional regions and 140+ a...

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

Popular Posts