Collections & LINQ · Lesson 6

Sort

OrderBy changes the sequence you read. It does not rewrite the array.

How it works

OrderBy(n => n) yields 1, then 4, then 9. The array numbers is still 4, 9, 1 afterwards: sorting builds a new sequence. First reads the sorted sequence, so the printed value is 1.

A working example

var numbers = new[] { 4, 9, 1 };
var sorted = numbers.OrderBy(n => n);
Console.WriteLine(sorted.First());

Expected output

1
Try this
Try the filter on a smaller list.