有
public String Authenticate(String configUrl, out String tokenId)
这个
__authenticator->Authenticate(
gcnew System::String(hostUrl),
gcnew System::String(temp)
);
在 C# 中等同于(考虑到 Authenticate 的签名)
__authenticator.Authenticate(
new String(hostUrl),
out new String(temp)
);
但在 C# 中你不能做 out new Something,你只能 out 到变量、字段...所以在 C# 中你需要这样做:
String temp2 = new String(temp);
__authenticator.Authenticate(
new String(hostUrl),
out temp2
);
并且,考虑到参数在out 中,您可以:
String temp2;
__authenticator.Authenticate(
new String(hostUrl),
out temp2
);
现在,在 C++/CLI 中,您拥有
System::String^ temp2 = gcnew System::String(temp);
__authenticator->Authenticate(
gcnew System::String(hostUrl),
temp2
);
或者,知道temp2 是out(注意ref 和out 之间的区别仅由C# 编译器检查,而不是由C++/CLI 编译器检查)
// agnostic of the out vs ref
System::String^ temp2 = nullptr;
// or knowing that temp2 will be used as out, so its value is irrelevant
// System::String^ temp2;
__authenticator->Authenticate(
gcnew System::String(hostUrl),
temp2
);