0

While reviewing Async and Await, I noticed that Task.WhenAll could be called with any number of parameters:

Threading.Tasks.Task.WhenAll(New Threading.Tasks.Task(New Action(Sub() Console.WriteLine("Hello"))),
                             New Threading.Tasks.Task(New Action(Sub() Console.WriteLine("Hello"))),
                             New Threading.Tasks.Task(New Action(Sub() Console.WriteLine("Hello"))),
                             New Threading.Tasks.Task(New Action(Sub() Console.WriteLine("Hello"))),
                             New Threading.Tasks.Task(New Action(Sub() Console.WriteLine("Hello"))))

Why does this work, but methods like Array.Reverse do not allow you to pass any number of parameters?

1 Answers1

0

Turns out that after looking at the code on the .Net Reference Source site, specifically the overload with an array of Tasks, and after looking at this SO post, I found that the params keyword (ParamArray in VB.Net) allows you to pass no arguments, any number of comma separated arguments of the specified type, or an array of the specified type.

You can think of it like destructuring an Array in Javascript or the args array in Python.

Community
  • 1
  • 1