LINQ Interview Question #39
What does Reverse do in LINQ?
Filtering, Projection, Ordering & Element Operators Junior Beginner
Quick Interview Answer
Reverse returns the elements of a sequence in the opposite order from their current enumeration order. It does not mean the same thing as sorting descending unless the sequence is already sorted in a meaningful ascending order.
Detailed Explanation
Reverse returns the elements of a sequence in the opposite order from their current enumeration order. It does not mean the same thing as sorting descending unless the sequence is already sorted in a meaningful ascending order.
If the intent is to sort by a property descending, OrderByDescending communicates that intent more clearly.
Code Example
var numbers = new[] { 1, 2, 3, 4 };
var reversed = numbers.Reverse();
// 4, 3, 2, 1