Passing a callback function to another class

前端 未结 7 1378
小鲜肉
小鲜肉 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条回答
  •  后悔当初
    2021-01-30 01:04

    You can pass it as Action - which means it is a method with a single parameter of type string that doesn't return anything (void) :

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

提交回复
热议问题