你如何获得一个多维数组在C#中的宽度和高度?多维、数组、宽度、如何获得

2023-09-03 11:50:08 作者:11.兜里有糖,心里不慌

我有一个数组定义的:

int [,] ary;
// ...
int nArea = ary.Length; // x*y or total area

这是一切都很好,错误我需要知道这个数组是在 X 是单独的尺寸。也就是说,它们 ary.Length 可能会返回12 - 但这是否意味着数组为4高3宽,或6个高2个宽

This is all well and good, bug I need to know how wide this array is in the x and y dimensions individually. Namely, they ary.Length might return 12 - but does that mean the array is 4 high and 3 wide, or 6 high and 2 wide?

我怎样才能检索到的信息?

How can I retrieve this information?

推荐答案

您使用阵.GetLength 与要检索维度的指标。

You use Array.GetLength with the index of the dimension you wish to retrieve.