Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
int[,] arr = new int[2,5]; var rows = arr.? var cols = arr.? Assert.Equals(3, rows); Assert.Equals(6, cols);
You can use GetLength(some-dimension-starting-from-0) on a array.
GetLength(some-dimension-starting-from-0)
var rows = arr.GetLength(0); var cols = arr.GetLength(1);
But rows will be 2 and columns 5.
var arr = new int[2,3]
Will give you:
arr[0,0] arr[0,1] arr[0,2] arr[1,0] arr[1,1] arr[1,2]
Add a comment
You can use GetLength() method of array that let you know what is the length of each dimension.
GetLength()
var rows = arr.GetLength(0); var columns = arr.GetLength(1);
Just to make clear, it gets the size, so in your example rows will be 2.
arr.GetLength(dimensionYouWant);
arr.GetLength(index)
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.