public class MyClass
{
delegate void MyDelegate(int myParam);
public MyClass(OtherObject obj)
{
//THIS IS THE IMPORTANT PART
obj.SomeCollection.Add((MyDelegate)MyFunction);
}
private void MyFunction(int myParam);
{
//...
}
}
试图在C++/CLI中实现同样的事情,看来我必须这样做:
MyDelegate del = gcnew MyDelegate(this, MyFunction);
obj->SomeCollection->Add(del);