LINQ Interview Question #8

What is IEnumerable<T>?

LINQ Fundamentals, Syntax, IEnumerable & IQueryable Junior Beginner

Quick Interview Answer

IEnumerable<T> represents a sequence that can be enumerated one element at a time. It is the fundamental generic interface used by LINQ to Objects.

Detailed Explanation

IEnumerable<T> represents a sequence that can be enumerated one element at a time. It is the fundamental generic interface used by LINQ to Objects.

When LINQ operators are applied to IEnumerable<T>, the operations normally execute as .NET code. Many operators use deferred execution and perform their work when the sequence is enumerated.

Code Example

IEnumerable<int> numbers = new[] { 1, 2, 3, 4 };

IEnumerable<int> result =
    numbers.Where(n => n > 2);

foreach (var number in result)
{
    Console.WriteLine(number);
}