我的问题很简单。 我怎么知道声明为......的数组的大小?
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.
更多推荐
发布评论