Passing a callback function to another class

前端 未结 7 1505
小鲜肉
小鲜肉 2021-01-30 00:39

I\'m basically trying to pass a method to another class to be called later, but can\'t quite figure this out in C# (I\'m still too used to Objective-C).

public c         


        
7条回答
  •  萌比男神i
    2021-01-30 01:18

    You have to first declare delegate's type because delegates are strongly typed:

    public void MyCallbackDelegate( string str );
    
    public void DoRequest(string request, MyCallbackDelegate callback)
    {
         // do stuff....
         callback("asdf");
    }
    

提交回复
热议问题