我有以下方法,它是 Google.Apis IDatastore 的实现
https://developers.google.com/api-client-library/dotnet/guide/aaa_oauth#web_applications :
public Task<T> GetAsync<T>(string key)
{
var account = GetAccountById(key);
return account;
}
以上是行不通的。我得到:
Cannot implicitly convert type 'Model.Account' to 'System.Threading.Tasks.Task'
所以我不确定如何返回我的帐户
。我认为这很简单,但我没有做到。
最佳答案
我认为 Task<T>
的正确实现会是这样的
public Task<T> GetAsync<T>(string key)
{
// Replace with actual logic
return Task.Factory.StartNew(() => default(T));
}
对于 Account
public Task<Account> GetAsync(string key)
{
return Task.Factory.StartNew(() => GetAccountById(key));
}
关于c# - 任务<T>如何返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27216638/