Cannot implicitly convert type from Task<>

后端 未结 3 720
逝去的感伤
逝去的感伤 2020-12-01 08:56

I am trying to master async method syntax in .NET 4.5. I thought I had understood the examples exactly however no matter what the type of the async method is (ie Task

3条回答
  •  有刺的猬
    2020-12-01 09:27

    The main issue with your example that you can't implicitly convert Task return types to the base T type. You need to use the Task.Result property. Note that Task.Result will block async code, and should be used carefully.

    Try this instead:

    public List TestGetMethod()  
    {  
        return GetIdList().Result;  
    }
    

提交回复
热议问题