如何找到二维数组的大小?

发布于 2024-09-30 14:57:20 字数 387 浏览 0 评论 0原文

如果我声明这个数组...

string[,] a = {
                  {"0", "1", "2"},
                  {"0", "1", "2"},
                  {"0", "1", "2"},
                  {"0", "1", "2"},
              };

那么我可以测量长度为

a.Length

12。如何测量其中数组的维度?如果我尝试...

a[0].Length

我会得到[]内的索引数量错误;预计2。什么给?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

自演自醉 2024-10-07 14:57:20

您需要数组的 GetLength() 方法:

a.GetLength(0);

http://msdn.microsoft.com /en-us/library/system.array.getlength.aspx

You want the GetLength() method of your array:

a.GetLength(0);

http://msdn.microsoft.com/en-us/library/system.array.getlength.aspx

银河中√捞星星 2024-10-07 14:57:20

使用 Array.Rank获取维数,然后使用 Array.GetLength( int size) 获取特定维度的长度。

Use Array.Rank to get number of dimensions and then use Array.GetLength(int dimension) to get the length of a specific dimension.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文