I do not understand why. There is an asynchronous method call

tasks = request.Sets .Select(x => _service.MethodAsync(...)) .ToArray(); 

Also give the declaration of the called function:

 public async Task<IReadOnlyDictionary<long, TValue>> MethodAsync(...) 

As you can see, it returns

 Task<IReadOnlyDictionary<long, TValue>> 

at the same time, then there is a block in which we wait for the thread and here is an incomprehensible thing for me:

 cache = (await Task.WhenAll(tasks)) .Select((x, i) => new KeyValuePair<int, IReadOnlyDictionary<long, TValue>>(request.Sets[i].Id, x)) .ToDictionary(x => x.Key, x => x.Value); 

Rider suggests that type x is IReadOnlyDictionary<long, TValue>> , and type i is int . Thus, it is not clear to me why Select expects a delegate with two arguments instead of a delegate with one argument of type IReadOnlyDictionary<long, TValue>> ?

  • Write x instead of (x, i) - it will work fine too (although you have i used, but these are details). Two overloads of the Enumerable.Select method. And the question is what? - Regent
  • 3
    You call the Select function overloaded, the second argument is the index of the element in the sequence - tym32167
  • @ tym32167 thanks - hedgehogues 2:55 pm

0