在 ac# 类中,我有以下内容:
public class Myclass
{
public Action<string, string> MyDelegate { get; set;}
public void CallingAction()
{
MyDelegate("string1", "string2");
}
}
在 C++/Cli 中,我想向委托添加一个新函数。
public ref class MyCliClass
{
public :
MyCliClass()
{
MyClass^ myClassInstance = gcnew MyClass();
MyCliDelegate^ myDelegateInstance = gcnew MyCliDelegate(this, &MyCliClass::FunctionToCall);
myClassInstance->MyDelegate += myDelegateInstance;
}
void FunctionToCall(string^ string1, string^ string2)
{
// Some stuff to do
}
private :
void delegate MyCliDelegate(string^,string^);
}
这给了我错误:
error C3365: operator '+' : differing operands of type 'System::Action<T1, T2> ^' and 'MyCliClass::FunctionToCall^'
如何简单地将“FunctionToCall”添加到 C# 委托中,以便在调用“CallingAction”时,也调用“FunctionToCall”?
谢谢
编辑/回答 这是新的 Cli/类
public ref class MyCliClass
{
public :
MyCliClass()
{
MyClass^ myClassInstance = gcnew MyClass();
myClassInstance->MyDelegate += gcnew Action<string^,string^>^(this, &MyCliClass::FunctionToCall);
}
void FunctionToCall(string^ string1, string^ string2)
{
// Some stuff to do
}
}