Junior — Middle
What class or data type is returned when using the Where method in LINQ?
sobes.tech AI
Answer from AI
The Where method in LINQ returns an object that implements the IEnumerable<T> interface. It is a deferred (lazy) sequence that, when enumerated, applies the specified filter condition to the source collection. The return type is usually IEnumerable<T>, where T is the type of elements in the source collection.
Example:
var numbers = new List<int> {1, 2, 3, 4, 5};
var evenNumbers = numbers.Where(n => n % 2 == 0); // evenNumbers has type IEnumerable<int>
foreach(var num in evenNumbers)
{
Console.WriteLine(num); // Will output 2 and 4
}