1 | initial version |
One possible method to group using the outcome of an asynchronous Task<string> and receive a grouping by string in C# is as follows:
List<Task<string>> tasks = new List<Task<string>>()
{
GetStringAsync("foo"),
GetStringAsync("bar"),
GetStringAsync("baz"),
};
Task<string>[] results = await Task.WhenAll(tasks);
var groups = results.GroupBy(s => s[0]);
foreach (var group in groups)
{
Console.WriteLine("{0}: {1}", group.Key, group.Count());
}
This will produce output like the following:
f: 1
b: 2