Currently I have a method with the signature public Task<IEnumerable<Descriptor>> GetAllDescriptors()
where Descriptor
is a public class I created. I then have various tasks that I call within this method like so:
var allDescriptors = Task.WhenAll(GetMovieDescriptorAsync, GetSongDescriptorAsync);
Since GetMovieDescriptorAsync
& GetSongDescriptorAsync
both return Task<Descriptor>
I know that the variable type of allDescriptors
is Task<Descriptor[]>
which is great. However if I try return allDescriptors
I get the error:
Cannot implicitly convert type 'System.Threading.Tasks.Task<Descriptor[]>' to 'System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<Descriptor>>'
However, if I change the method signature to public async Task<IEnumerable<Descriptor>> GetAllDescriptors()
and then I try return await allDescriptors
it works and I get the desired <IEnumerable<CompletionInfo>
in the calling function:
var descriptors = await GetAllDescriptors();
Why is that and how can I return the expected IEnumerable<Descriptor>
without having to use async and await?