How can I use a method async Task and return string, and then how do I pass a delegate for that method to a constructor and use it later?

前端 未结 4 532
滥情空心
滥情空心 2021-01-20 15:05

I have this method that returns string:

public string SendResponse(HttpListenerRequest request)
{
    string result = \"\";
    string key = req         


        
4条回答
  •  深忆病人
    2021-01-20 15:32

    Declare SendResponse as a Task. This says that this Task will return a string.

    public async Task SendResponse(HttpListenerRequest request)
    {
        ...
    }
    

    And in whenever you're calling it:

    string result = await SendRespone(request);
    

提交回复
热议问题