Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从阵列复制<;未签名短消息>;到C CLI中的未签名短[]吗? 我正在为一个C++ API做一个C++ CLI包装器。C API的结构包含一个由四个无符号短字符组成的数组和一个由四个整数组成的数组。因此,我为C代码创建了一个类似的类,以便在调用包装器函数时使用 // C Structure typedef struct c_Struct_ { unsigned short uShorts[4]; int ints[4]; } c_Struct; // C++ CLI Class public ref class CliClass { public: property array<unsigned short>^ UnsignedShorts { array<unsigned short>^ get() { return _unsignedShorts; } } property array<int>^ Ints { array<int>^ get() { return _ints; } } CliClass(array<unsigned short>^ us, array<int> i) { _unsignedShorts = us; _ints = i; } private: array<unsigned short>^ _unsignedShorts; array<int>^ _ints; }_C#_C++_C_Arrays - Fatal编程技术网

C# 如何从阵列复制<;未签名短消息>;到C CLI中的未签名短[]吗? 我正在为一个C++ API做一个C++ CLI包装器。C API的结构包含一个由四个无符号短字符组成的数组和一个由四个整数组成的数组。因此,我为C代码创建了一个类似的类,以便在调用包装器函数时使用 // C Structure typedef struct c_Struct_ { unsigned short uShorts[4]; int ints[4]; } c_Struct; // C++ CLI Class public ref class CliClass { public: property array<unsigned short>^ UnsignedShorts { array<unsigned short>^ get() { return _unsignedShorts; } } property array<int>^ Ints { array<int>^ get() { return _ints; } } CliClass(array<unsigned short>^ us, array<int> i) { _unsignedShorts = us; _ints = i; } private: array<unsigned short>^ _unsignedShorts; array<int>^ _ints; }

C# 如何从阵列复制<;未签名短消息>;到C CLI中的未签名短[]吗? 我正在为一个C++ API做一个C++ CLI包装器。C API的结构包含一个由四个无符号短字符组成的数组和一个由四个整数组成的数组。因此,我为C代码创建了一个类似的类,以便在调用包装器函数时使用 // C Structure typedef struct c_Struct_ { unsigned short uShorts[4]; int ints[4]; } c_Struct; // C++ CLI Class public ref class CliClass { public: property array<unsigned short>^ UnsignedShorts { array<unsigned short>^ get() { return _unsignedShorts; } } property array<int>^ Ints { array<int>^ get() { return _ints; } } CliClass(array<unsigned short>^ us, array<int> i) { _unsignedShorts = us; _ints = i; } private: array<unsigned short>^ _unsignedShorts; array<int>^ _ints; },c#,c++,c,arrays,C#,C++,C,Arrays,但我得到了一个错误:IntelliSense:不能为每个赋值将“System::Object^”类型的值赋值给“unsigned short”类型的实体。正确的语法是什么?首先取消绑定引用类型,尝试以下操作: results.uShorts[0] = (unsigned short)UnsignedShorts[0]; 代码是正确的,您将看到您的程序编译得很好。没有任何东西被装箱。这是IntelliSense解析器中的一个错误。很奇怪,很难想象它是怎么搞砸的。解析器是由另一家公司制造的,这并非

但我得到了一个错误:IntelliSense:不能为每个赋值将“System::Object^”类型的值赋值给“unsigned short”类型的实体。正确的语法是什么?

首先取消绑定引用类型,尝试以下操作:

results.uShorts[0] = (unsigned short)UnsignedShorts[0];

代码是正确的,您将看到您的程序编译得很好。没有任何东西被装箱。这是IntelliSense解析器中的一个错误。很奇怪,很难想象它是怎么搞砸的。解析器是由另一家公司制造的,这并非完全罕见。爱迪生设计小组以编写唯一能够正确实现C++03标准的编译器而闻名。不过,C++/CLI让他们心痛不已

有两种基本解决方法,您可以使用字段而不是属性:

   c_Struct ToStruct() {
        c_Struct results;
        results.uShorts[0] = _unsignedShorts[0];
        // etc...
   }
但这并不能解决使用该类的代码的问题。您可以将它们改为索引属性:

property unsigned short UnsignedShorts[int]
{
    unsigned short get(int index) {
        return _unsignedShorts[index];
    }
}
// Same for the Ints property.

另一个解决方法是首先指定一个临时局部变量

array<int> ^temp = ArrayOfIntsProperty;
int j = temp[0];
array^temp=ArrayOfIntsProperty;
int j=温度[0];

<>这只会影响属性——当调用索引时,返回托管数组的函数看起来是正常工作的。< /P>您是否尝试过取消句柄?看起来好像忘记添加“代码> ^ <代码>:这里:代码> CliClass(数组^,数组i)< /C>(第二个参数),这样在C++ CLI框中自动地排列,但需要强制转换才能取消X轴?好的,我会尽量记住的。根本不会发生拳击。演员阵容在愚弄IntelliSense解析器方面很有效。@HansPassant谢谢你的解释。同时感谢您在MSDN论坛上作为nobugz提供的帮助。:)
array<int> ^temp = ArrayOfIntsProperty;
int j = temp[0];