Consider the following method:
(minimum working example - I am aware of it being effectively synchronous)
public static Task<List<int>> GetAll()
{
var ints = new List<int>();
ints.Add(1);
ints.Add(2);
ints.Add(3);
return Task.FromResult(ints);
// return Task<List<int>>.FromResult(ints); <-- what's the difference between this and the line before it?
}
I can use both ways, returning with Task.FromResult
or Task.FromResult<TResult>
. What is the difference between them? When would I use which? Why are there two possibilities that lead to the likely same result?
Update: As they are both the same - any examples where the explicitely typed one would be required?
>(ints)`, you've explicitly provided a type value for `TResult`, meaning that *only* `List` can be accepted as a parameter. In terms of compiler output, they are equivalent.
– spender Sep 09 '19 at 14:51