gpt4 book ai didi

c# - IEnumerable 返回类型 C# C++

转载 作者:太空宇宙 更新时间:2023-11-03 20:02:27 25 4
gpt4 key购买 nike

我有 C# 接口(interface),方法签名如下:

IEnumerable<string> Myfun();

在 C++/CLR 中接收返回字符串的数据类型是什么?

我试过了

IEnumerable<std::string> ^abc = myObject.Myfun();

我得到这个错误:错误 C3225:“T”的泛型类型参数不能是“std::string”,它必须是值类型或引用类型的句柄

最佳答案

使用这个:

IEnumerable<String^>^ abc = myObject.Myfun();

您需要使用 System::String^ 作为您的类型,而不是 C++ 的 std::string

如果你需要使用std::string传递给其他C++代码,你需要使用

std::string myCPPstring = marshal_as<std::string>(myDotNetString);

关于c# - IEnumerable 返回类型 C# C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26494511/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com