Task — reference type. ValueTask — struct for performance.
Task:
1public async Task<int> GetDataAsync() {2 return await httpClient.GetIntAsync("url");3}
ValueTask:
1public async ValueTask<int> GetDataAsync() {2 if (cache.TryGetValue("key", out int value)) {3 return value; // No allocation!4 }5 return await httpClient.GetIntAsync("url");6}
When to use ValueTask:
Warning: