如何创建数组作为托管类的属性? [英] How can I create arrays as properties of managed classes?

查看:74
本文介绍了如何创建数组作为托管类的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好;

您可以在Microsoft C ++中将数组作为托管类的属性吗?
不必使用gcnew函数为数组分配内存?

无法编译:

公共引用类foo_class
{int array01 [22]; }

还有另一种方法可以使数组位于同一内存块内吗?
与该类的实例一样?

除了必须执行以下操作之外,还可以通过其他任何方式完成此操作吗:

公共引用类foo_class
{
数组< int> ^ array01;

foo_class()
{array01 = gcnew< int> (22); }
}

谢谢!!!

解决方案

我对此表示怀疑.如果您不想自己调用gcnew,则可以使用.NET容器,然后使用该容器提供ToArray方法.


克里斯蒂安;

因此,对于将成为类属性的每个数组,
我必须为每个分配额外的缓冲区空间
类/实例中的数组?


公共引用类foo_class
{
数组[int] ^ array01;
数组[int] ^ array02;
数组[long] ^ array03;
数组[char] ^ array04;

foo_class()
{
array01 = gcnew [int](22);
array02 = gcnew [int](33);
array03 = gcnew [long](7);
array04 = gcnew [char](333);
}
}


无法在一个块内分配所有空间
(用于实例以及其中的任何和所有数组的空间)?

谢谢您的回复!!!!


这有点让我烦恼,我要请Nish看看,他是这方面的专家. /blockquote>

Hi all;

Can you have an array as a property of a managed class in Microsoft C++
without having to use the gcnew function to allocate memory for the array?

This will not compile:

public ref class foo_class
{ int array01[22]; }

Is there another way to get the array to be within the same block of memory
as that for the instance of the class?

Can this be done in any way other than having to do the following?:

public ref class foo_class
{
array <int> ^ array01;

foo_class ()
{ array01 = gcnew <int> (22); }
}

Thanks!!!

解决方案

I doubt it. You could perhaps use a .NET container, which then gives you the ToArray method, if you don''t want to call gcnew yourself.


Hi Christian;

So, for every array that is to be a property of a class,
I have to allocate additional buffer space for each and every
array within the class/instance?


public ref class foo_class
{
array [int] ^ array01;
array [int] ^ array02;
array [long] ^ array03;
array [char] ^ array04;

foo_class ()
{
array01 = gcnew [int] (22);
array02 = gcnew [int] (33);
array03 = gcnew [long] (7);
array04 = gcnew [char] (333);
}
}


There is no way to allocate all of the space within one block
(for the instance along with space for any and all arrays within)?

Thanks for the response!!!


This is a little over my head, I''m going to ask Nish to look at it, he''s the expert on this stuff.


这篇关于如何创建数组作为托管类的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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