Sign in to track progress and bookmarks.
Before LINQ, working with data was a mess of nested foreach loops and manual boolean flags. LINQ (Language Integrated Query) brought functional programming patterns to C#, transforming how we transform data.
Imperative code tells the computer HOW to do something (step-by-step). Declarative code (LINQ) tells the computer WHAT you want.
var topStudents = new List<string>();
foreach (var s in students) {
if (s.Grade > 90) {
topStudents.Add(s.Name);
}
}
var topStudents = students.Where(s => s.Grade > 90)
.Select(s => s.Name);
LINQ is heavily inspired by functional languages like Haskell. It treats data as Immutable Streams. When you run a LINQ query, you aren't changing the original list; you are creating a new projection of it.
Q: "Does LINQ make code slower?"
Architect Answer: "The overhead of LINQ is negligible in 99% of business applications. The benefits in Readability and Maintainability far outweigh the micro-seconds of performance loss. However, for a high-performance socket server or a low-latency game engine, you might prefer raw loops to avoid delegate allocations. Premature optimization is the root of all evil—write clean LINQ first."
Quizzes linked to this course—pass to earn certificates.
On this page
1. Imperative vs Declarative 2. The "Functional" Mindset 3. Architect Insight