If I declare this array...
string[,] a = { {"0", "1", "2"}, {"0", "1", "2"}, {"0", "1", "2"}, {"0", "1", "2"}, };
Then I can measure the length with
a.Length
which is 12. How do I measure the dimension of the arrays within? If I try...
a[0].Length
I get Wrong number of indices inside []; expected 2
. What gives?
Turn the 2d array into a 1d array ( List<Integer> ), then loop through the 1d array counting the duplicates as you find them and removing them so you don't count them more than once.
We use arrayname. length to determine the number of rows in a 2D array because the length of a 2D array is equal to the number of rows it has. The number of columns may vary row to row, which is why the number of rows is used as the length of the 2D array.
Put all the numbers in a Set and just match the size of array and set. If both are equal then all your numbers in array are unique.
You want the GetLength() method of your array:
a.GetLength(0);
http://msdn.microsoft.com/en-us/library/system.array.getlength.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With