.NET 中的二进制数据? (C++/CLI)
在 .NET 中存储二进制数据的首选方式是什么?
我已经尝试过这个:
byte data __gc [] = __gc new byte [100];
并收到此错误:
error C2726: '__gc new' may only be used to create an object with managed type
有没有办法管理字节数组?
What's the prefered way to store binary data in .NET?
I've tried this:
byte data __gc [] = __gc new byte [100];
And got this error:
error C2726: '__gc new' may only be used to create an object with managed type
Is there a way to have managed array of bytes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不知道这样做的首选方法。 但如果您只想编译它,以下是我的计算机上的 C++/CLI CLRConsole 项目的工作代码。
输出:
a
是托管字节的托管数组。b
是无符号字符的托管数组。 C++ 似乎没有内置byte
数据类型。I don't know the preferred way of doing this. But if you only want it compiled, the following are working code from my C++/CLI CLRConsole project from my machine.
Output:
a
is managed array of managed byte. Andb
is managed array of unsigned char. C++ seems not to havebyte
data type built in.CodeProject: C++/CLI 中的数组
据我所知 '__gc new'语法已弃用,请尝试以下操作:
我注意到您在使用 cli 命名空间时遇到问题。 阅读MSDN 上的命名空间来解决您的问题问题。
CodeProject: Arrays in C++/CLI
As far as I know '__gc new' syntax is deprecated, try following:
I noted that you're having problems with cli namespace. Read about this namespace on MSDN to resolve your issues.
您使用的是托管 C++ 还是 C++/CLI? (我可以看到 Jon Skeet 编辑了问题以将 C++/CLI 添加到标题中,但对我来说,您实际上正在使用托管 C++)。
但无论如何:
在托管 C++ 中,您可以这样做:
在 C++/CLI 中,它看起来像这样:
Are you using Managed C++ or C++/CLI? (I can see that Jon Skeet edited the question to add C++/CLI to the title, but to me it looks like you are actually using Managed C++).
But anyway:
In Managed C++ you would do it like this:
In C++/CLI it looks like this: