Write the program encountered need to get a two-dimensional array of actual data in the number of rows, see a few blog to get the array row count is actually an array. Rank method. This is the way to get the dimension ah, I posted below the correct method I found, very practical.
/// <summary>///gets the number of rows in the two-dimensional array that actually have data/// </summary> Public Staticlist<int> Gethasvaluerowindex (string[,] arr) { varHasvaluerowindex =Newlist<int>(); for(vari =0; I < arr. GetLength (0); i++) { for(varj =0; J < arr. GetLength (1); J + +) { if(!string. IsNullOrEmpty (Arr[i, J])) {hasvaluerowindex.add (i); Break; } } } returnHasvaluerowindex;}//Demostring[,] a =New string[9,3];a[0,0] ="a"; a[2,0] ="b"; a[4,0] ="C"; a[6,0] ="D"; a[8,0] ="e";vararr =Gethasvaluerowindex (a); Console.WriteLine ("HasValue Row Count:"+arr. Count); arr. ForEach (o=Console.WriteLine (o));/*HasValue Row count:5 0 2 4 6 8*/
int[,] array =New int[,] {{1,2,3},{4,5,6},{7,8,9},{Ten, One, A}};//defines a two-dimensional array of 4 rows and 3 columnsintdimension= Array. Rank;//gets the number of dimensions of the array; a value of 2introw = arr. GetLength (0);//returns the length of the first dimension (the so-called "number of Rows") (the number of rows for all data is not the number of rows that actually have data stored)intCol = array. GetLength (1);//Gets the number of elements in the specified dimension, which is the number of columns. (0 is the first dimension, 1 represents the second dimension); The value is 3intCol = array. GetUpperBound (0)+1;//gets the upper limit of the index for the specified dimension, plus a 1 is the total number, which represents the number of rows in a two-dimensional arrayintnum = array. Length;//gets the length of the entire two-dimensional array, that is, the number of all the elements
Gets the number of rows in the two-dimensional array that actually have data