from n in numbers where n = 5 select n is actually the syntactic sugar for numbers.Where(n => n == 5) . This way you filter a list of numbers equal to 5 using the LINQ expression.
LINQ, however, appreciates the lazy. This means that the object returned by numbers.Where(n => n == 5) (IEnumerable) is not a list of numbers equal to five. The list is created only when necessary, that is, when trying to access IEnumerable elements.
ToList copies the contents of this IEnumerable to the list, which means that the expression must be evaluated right now.
source share