如何检查数组 size,N是一个自然数?(How to check array size, with N a natural number?)

编程入门 行业动态 更新时间:2024-10-28 16:25:34
如何检查数组 size,N是一个自然数?(How to check array size, with N a natural number?)

我的问题很简单。 我怎么知道声明为......的数组的大小?

array<ObjectType^, 3>

我已经看到通过下一个方式访问他们的元素:

array_var[i,j,k];

那么,我怎么知道不同尺寸的大小呢?

My question is simple. How can I know the size of an array declared as...?

array<ObjectType^, 3>

I've seen that the access to their elements is made by the next way:

array_var[i,j,k];

So, how can I know the size of the different dimensions?

最满意答案

看起来你在c ++ / cli中使用托管数组(虽然截至撰写本文时,你尚未确认这一点)。

假设您正在使用cli::array实例,您可以从其文档中看到它继承自System::Array ,并且该类的所有方法都适用。 如果您阅读该类自己的文档 ,您会发现有一个Array::GetLength(Int32)方法可以让您获得给定维度的大小(请参阅此方法的文档)。

例如,

array<ObjectType^, 3>^ array_var = gcnew array<ObjectType^, 3>(3, 4, 5);

声明一个大小为3*4*5的新3d数组。

array_var->GetLength(2)

将返回5 (因为尺寸从0开始编号,像往常一样)。 您还可以使用array_var->Rank来获取数组的维数。

It looks like you're using a managed array in c++/cli (though as of time of writing, you haven't got round to confirming this yet).

On the assumption that you are using a cli::array instance, you can see from its documentation that it inherits from System::Array, and all methods of that class are applicable. If you read that class' own documentation, you'll find that there's an Array::GetLength(Int32) method that lets you get the size of a given dimension (see that method's documentation here).

For example,

array<ObjectType^, 3>^ array_var = gcnew array<ObjectType^, 3>(3, 4, 5);

declares a new 3d array of size3*4*5.

array_var->GetLength(2)

will return 5 (because the dimensions are numbered from 0, as usual). You can also use array_var->Rank to get the number of dimensions for the array.

更多推荐

本文发布于:2023-08-05 18:14:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1435841.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:是一个   自然数   数组   size   number

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!