Advanced LINQ — extension methods and deferred execution.
Deferred vs immediate:
1// Deferred — executed on enumeration2var query = list.Where(x => x > 5);34// Immediate — executed now5var result = list.Where(x => x > 5).ToList();
Custom operator:
1public static IEnumerable<T> WhereIf<T>(2 this IEnumerable<T> source,3 bool condition,4 Func<T, bool> predicate)5{6 return condition ? source.Where(predicate) : source;7}
IQueryable vs IEnumerable:
Performance: