Collections & a First Taste of LINQ
Fundamentals closes with C#'s everyday collections — and a first look at the feature that touches nearly every one of them, deferred to Course 2's own full chapter, but too central to leave out entirely here.
List<T> — A Growable Collection
Nearly identical in behavior to java1-8's own List/ArrayList — grows automatically, generic. C#'s generics are reified rather than erased, a real difference Course 2's own Generics In Depth chapter covers in full; this chapter stays at the surface level.
Dictionary<TKey, TValue>
Comparable to java1-8/java2-2's own Map/HashMap — key-value pairs, average constant-time lookup. C#'s indexer syntax (ages["Alice"]) reads slightly more concisely than Java's explicit .put()/.get() calls, though the underlying idea is identical.
Iterating — foreach
Directly comparable to Java's own enhanced for loop — same purpose, different keyword.
A First Taste of LINQ
LINQ — Language Integrated Query — shipped in C# 3.0, back in 2007, genuinely comparable to java2-4's own Streams API but arriving seven years earlier. Another "C# first" moment, like csharp1-3's own switch expressions. LINQ offers two syntaxes for the same underlying query: fluent method chaining (.Where().Select()), and a genuinely unique SQL-like query syntax baked directly into C#'s own grammar — something neither Java nor most other languages on this site offer as native syntax at all.
Why Preview LINQ Now
LINQ works over anything implementing IEnumerable<T> — which includes List<T>, Dictionary<TKey,TValue>, arrays, and every collection this chapter just introduced. That's exactly why it belongs here rather than waiting entirely for Course 2 — it's the natural next step for everything just covered, not a separate, unrelated topic.
| Aspect | Java Streams (java2-4) | C# LINQ |
|---|---|---|
| Arrival | Java 8 (2014) | C# 3.0 (2007) — first |
| Fluent chaining | .filter().map().collect() | .Where().Select() |
| SQL-like query syntax | not available | from...where...select, built into the grammar |
IEnumerable<T> and IQueryable<T>, and LINQ's full operator vocabulary are all Course 2 material — this chapter only establishes that LINQ exists and roughly what it looks like.
Coding Challenges
Create a List<int> of at least six numbers, then use LINQ method syntax to filter for numbers greater than 10 and print the result using foreach.
📄 View solutionCreate a Dictionary<string, int> of at least four name/age pairs, then write the same query twice — once using LINQ method syntax and once using query syntax — to find everyone with age 30 or older, printing both results to show they match.
📄 View solutionWrite a short comment explaining why LINQ can operate over a List<T>, a Dictionary<TKey,TValue>, and a plain array all with the same syntax, referencing IEnumerable<T> directly.
📄 View solutionChapter 8 Quick Reference — Course 1 Complete
- List<T> and Dictionary<TKey,TValue> behave comparably to java1-8/java2-2's List and Map
- foreach is directly comparable to Java's enhanced for loop
- LINQ shipped in C# 3.0 (2007), seven years before java2-4's own Streams API
- LINQ offers both fluent method syntax and a genuinely unique SQL-like query syntax built into the language grammar
- LINQ works over anything implementing IEnumerable<T> — lists, dictionaries, and arrays alike
- C# Fundamentals is now complete. Course 2 (Intermediate/Advanced) begins with Generics In Depth — C#'s reified generics, a genuine opposite design choice from java2-1's own type erasure.