LINQ preview: Where, Select, OrderBy, Take/Skip; deferred execution
Build small LINQ pipelines over IEnumerable : filter with Where, transform with Select, order with OrderBy, and learn deferred execution vs materialization.
LINQ preview: Where, Select, OrderBy, Take/Skip; deferred execution is a free C# Academy lesson on CoddyKit — lesson 3 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the C# Academy learning path, one of 3 lessons in the course, and your progress syncs across the web and the CoddyKit app.
LINQ overview
Goal: Use tiny LINQ pipelines to filter, transform, and order data.
- Where (filter)
- Select (map)
- OrderBy, Take/Skip
- Deferred execution & materialization
Where + Select
Chain Where (filter) then Select (transform). Read left-to-right.
using System;
using System.Linq;
public class Program
{
public static void Main(string[] args)
{
int[] data = new int[] { 1, 2, 3, 4, 5, 6 };
// Filter even numbers, then square them
var query = data.Where(x => x % 2 == 0)
.Select(x => x * x);
foreach (int n in query)
{
Console.WriteLine(n); // 4, 16, 36
}
}
}
OrderBy + Take
Sort with OrderBy (and ThenBy), limit with Take.
using System;
using System.Linq;
public class Program
{
public static void Main(string[] args)
{
string[] names = new string[] { "Zoe", "Ada", "Alan", "Bob" };
var top2 = names.OrderBy(s => s.Length) // shortest first
.ThenBy(s => s) // tie-breaker
.Take(2);
foreach (string s in top2)
{
Console.WriteLine(s); // Ada, Bob
}
}
}
Projection (anonymous type)
Select can create anonymous objects for quick shape changes (Word, Length).
using System;
using System.Linq;
public class Program
{
public static void Main(string[] args)
{
string[] words = new string[] { "map", "filter", "reduce" };
var info = words.Select(w => new { Word = w, Length = w.Length });
foreach (var x in info)
{
Console.WriteLine(x.Word + " (" + x.Length + ")");
}
}
}
Deferred execution
Deferred: Query runs when you iterate. Changes to the source before enumeration affect results.
using System;
using System.Linq;
using System.Collections.Generic;
public class Program
{
public static void Main(string[] args)
{
List<int> numbers = new List<int> { 1, 2, 3 };
var q = numbers.Where(x => x > 1); // not executed yet
numbers.Add(4); // modify source before enumeration
foreach (int x in q) // executes here
{
Console.WriteLine(x); // 2, 3, 4
}
}
}
Materialize & syntax
Use ToList/ToArray to execute and store results. Query syntax is another way to write the same pipeline.
using System;
using System.Linq;
public class Program
{
public static void Main(string[] args)
{
int[] data = new int[] { 3, 1, 2 };
// Method syntax + materialize
var sorted = data.OrderBy(x => x).ToList(); // executes now
data[0] = 100; // will not affect 'sorted' (already materialized)
foreach (int n in sorted) { Console.WriteLine(n); } // 1,2,3
// Query syntax (equivalent)
var query =
from x in data
where x < 50
select x * 2;
foreach (int n in query) { Console.WriteLine(n); } // 2,4
}
}
Deferred execution meaning
Recap
Recap: Build pipelines with Where, Select, OrderBy, and Take/Skip. LINQ is deferred—materialize with ToList/ToArray when you need stable results.
Frequently asked questions
Is the “LINQ preview: Where, Select, OrderBy, Take/Skip; deferred execution” lesson free?
Yes — the full text of “LINQ preview: Where, Select, OrderBy, Take/Skip; deferred execution” is free to read here on the web, and the C# Academy course includes 3 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the C# Academy course, upgrade to CoddyKit PRO.
What will I learn in “LINQ preview: Where, Select, OrderBy, Take/Skip; deferred execution”?
Build small LINQ pipelines over IEnumerable : filter with Where, transform with Select, order with OrderBy, and learn deferred execution vs materialization. You practise C# Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start C# Academy?
No prior experience is required. C# Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 3, so you can start here or from the beginning and move at your own pace.
How long does the “LINQ preview: Where, Select, OrderBy, Take/Skip; deferred execution” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this C# Academy lesson?
Yes. Every C# Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Arrays, slicing, List , Dictionary
- foreach patterns; collection initializers
- LINQ preview: Where, Select, OrderBy, Take/Skip; deferred execution