A LINQ expression that uses a lambda expression without the async keyword can specify an index. For example:
var list = FileList.Select((file, index) => new { Index=index, Filename=file });
I am trying to obtain the index while using the async keyword. For example:
await Task.WhenAll(urlList.Select(async url =>
{
byte[] urlContents = await GetWebPageAsync(url);
lock (Locker) { webResults.Add(URLContents); }
}));
The reason I would like to obtain the index is so that the web page contents can be stored in an array instead of using a lock statement or searching within the collection for the index.
When I try to add an index to the above query, it gives compiler errors.
Is there a way to specify the index in the above query, or can another LINQ expression be used (other than Select) that supports using an async lambda expression with an index?