The following snippet compiles, but I\'d expect it to await the task result instead of giving me a List
.
var foo = bars.Sel
does it have a certain use
Sure. With async and await inside a LINQ statement you can e.g. do something like this:
var tasks = foos.Select( async foo =>
{
var intermediate = await DoSomethingAsync( foo );
return await DoSomethingElseAsync( intermediate );
} ).ToList();
await Task.WhenAll(tasks);
Without async/await inside a LINQ statement you're not awaiting anything inside the LINQ statement, so you can't process the result, or await for something else.
Without async/await, in the LINQ statement you're only starting tasks, but not waiting for them to complete. They'll still complete eventually, but it'll happen long after the control will leave the LINQ statement, so you can only access their results after the WhenAll
line will complete, but not inside the LINQ statement.