Skip to content

In memory collections

Context: LINQ to Objects works on any IEnumerable<T> (arrays, lists, dictionaries, custom collections). All operations are performed in memory.

List<string> fruits = new() { "apple", "banana", "cherry" };
var longFruits = fruits.Where(f => f.Length > 5);
  • Use streaming operators for large collections
  • Materialize with ToList() when query is reused multiple times

Data processing in console apps: Read a CSV file into a list of objects, then use LINQ to filter, group, and aggregate.

Example: In System.IO you can read lines with File.ReadLines and use LINQ directly.