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

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

问题描述

我有一个数组定义的:

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.

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

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