METHOD
Enumerable.ToLookup
Materializes a one-to-many lookup from a sequence. Multiple elements may share a key. Accessing a missing key yields an empty sequence rather than throwing.
Formal Syntax & Structure
csharp syntaxcsharp
items.ToLookup(keySelector)Working Example
Example Snippetcsharp
using System;using System.Linq;var groups = new[] { "a", "bb", "c" }.ToLookup(s => s.Length);Console.WriteLine(groups[1].Count()); // 2