ADVERTISEMENT
Google AdSense Slot (headerLeaderboard)
Set your Publisher ID in src/config/ads.ts to display live ads.
C# Tutorial• 7 min read
LINQ: Language Integrated Query
Fluent method syntax, Where, Select, OrderBy, GroupBy, and deferred execution
LINQ brings native declarative SQL-like querying directly into C#, enabling filtering, projection, sorting, and grouping on in-memory collections or database entities.
Fluent LINQ Operations & Deferred Execution
Where(predicate): Filters elements.
Select(transform): Projects elements into new structures.
OrderBy() / OrderByDescending(): Sorts elements.
Deferred Execution: LINQ queries do NOT execute when defined; they execute when enumerated (e.g. via foreach, .ToList(), or .First()).
Fluent LINQ Pipeline in Action
using System.Linq;
public record Student(string Name, int Grade, string Track);
var students = new List<Student> {
new("Alice", 95, "Backend"),
new("Bob", 58, "Frontend"),
new("Charlie", 88, "Backend"),
new("Diana", 92, "Backend")
};
// LINQ Pipeline: Filter passing backend students, sort descending, extract names
var honorRoll = students
.Where(s => s.Grade >= 80 && s.Track == "Backend")
.OrderByDescending(s => s.Grade)
.Select(s => s.Name)
.ToList();
Console.WriteLine(string.Join(", ", honorRoll)); // Alice, Diana, CharlieADVERTISEMENT
Google AdSense Slot (inContentBanner)
Set your Publisher ID in src/config/ads.ts to display live ads.
Test Yourself With Exercise
What is "Deferred Execution" in LINQ?