下面的 C# 代碼public async Task<T> GetValueOrCreateAsync<T>(string key, Func<T> factory)
{ //..
var value = await factory();
}編譯時會報錯CS1061 'Func<T>' does not contain a definition for 'GetAwaiter' and no extension method 'GetAwaiter' accepting a first argument of type 'Func<T>' could be found (are you missing a using directive or an assembly reference?)
1 回答

慕哥9229398
TA貢獻(xiàn)1877條經(jīng)驗 獲得超6個贊
public async Task<T> GetValueOrCreateAsync<T>(string key, Func<Task<T>> factory) { //.. var value = await factory(); return default(T); }
Func<T> - > Func<Task<T>>
- 1 回答
- 0 關(guān)注
- 787 瀏覽
添加回答
舉報
0/150
提交
取消