How does Task become an int?

后端 未结 2 1245
醉梦人生
醉梦人生 2020-11-28 17:53

We have this method:

async Task AccessTheWebAsync()
{ 
    HttpClient client = new HttpClient();

   Task getStringTask = client.Get         


        
2条回答
  •  Happy的楠姐
    2020-11-28 18:45

    No requires converting the Task to int. Simply Use The Task Result.

    int taskResult = AccessTheWebAndDouble().Result;
    
    public async Task AccessTheWebAndDouble()
    {
        int task = AccessTheWeb();
        return task;
    }
    

    It will return the value if available otherwise it return 0.

提交回复
热议问题