Challenge 3: Why LINQ Works Identically Across List, Dictionary, and Array — Possible Solution ==================================================================== // LINQ's operators (Where, Select, and the rest) are not written // specifically against List, Dictionary, or arrays // individually. Instead, they're written against a single, much more // general interface: IEnumerable. Any type that implements // IEnumerable -- meaning it can produce a sequence of elements one // at a time -- automatically gains access to every LINQ operator, // with no extra work required on that type's part. // // List implements IEnumerable directly. Dictionary implements IEnumerable> (which // is itself an IEnumerable with T = KeyValuePair). // Arrays implement IEnumerable too, built into the runtime itself. // Because all three ultimately satisfy the exact same interface, a // method like Where(predicate) can be written ONCE, generically, // against IEnumerable, and it automatically works correctly no // matter which of the three concrete types actually produced the // sequence being filtered. // // This is why the chapter's own numbers array example, this file's // own List and Dictionary examples, and any other // IEnumerable source can all be queried with the identical // .Where()/.Select() syntax -- the underlying collection type is // irrelevant to LINQ; only the shared IEnumerable contract matters. WHY THIS WORKS AS AN ANSWER ------------------------------ This correctly identifies IEnumerable as the single shared interface LINQ's operators are written against, explaining why the chapter's own claim ("LINQ works over anything implementing IEnumerable") holds uniformly across List, Dictionary, and arrays despite their otherwise very different internal structures.