你如何获得多维数组的宽度和高度? [英] How do you get the width and height of a multi-dimensional array?

查看:45
本文介绍了你如何获得多维数组的宽度和高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我定义了一个数组:

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

这一切都很好,但我需要分别知道这个数组在 xy 维度上的宽度.即,ary.Length 可能返回 12 - 但这是否意味着数组是 4 高和 3 宽,还是 6 高和 2 宽?

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

如何检索这些信息?

推荐答案

您使用 Array.GetLength 带有您要检索的维度的索引.

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

这篇关于你如何获得多维数组的宽度和高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆