Passing a callback function to another class

前端 未结 7 1507
小鲜肉
小鲜肉 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:16

    You could change your code in this way:

    public delegate void CallbackHandler(string str);
    
    public class ServerRequest
    {
        public void DoRequest(string request, CallbackHandler callback)
        {
            // do stuff....
            callback("asdf");
        }
    }
    

提交回复
热议问题