To group a collection using LINQ, you can use the GroupBy() method:
using System.Linq;
List<string> names = new List<string> { "John", "Jane", "Doe" };
var groups = names.GroupBy(x => x.Length);
foreach (var group in groups)
{
Console.WriteLine($"Names with {group.Key} characters:");
foreach (string name in group)
{
Console.WriteLine(name);
}
}@csharp_1001_notes
