Just trying to figure it out better. I know this is due to defective execution
But what does this cause the method to not receive calls immediately. This is from EduLinq from JonSkeet.
public static partial class Enumerable { public static IEnumerable<TSource> Where<TSource>( this IEnumerable<TSource> source, Func<TSource, bool> predicate) { if (source == null) { throw new ArgumentNullException("source"); } if (predicate == null) { throw new ArgumentNullException("predicate"); } foreach (TSource item in source) { if (predicate(item)) { yield return item; } } } }
This is where I use it.
List<int> list = new List<int>() { 1, 3, 4, 2, 8, 1 }; var s = list.Where(x => x > 4); var result = s.ToList();
My question, although Where is the static method in IEnumerable, is why it is not being called in list.where (). But it is called s.ToList ().
I have a breakpoint on Enumerable.Where (), it does not fall on s = list.Where(x => x > 4) , but a breakpoint falls on s.ToList()
After I saw a comment from YUCK Why does LINQ have deferred execution? I add this to the question.
Please let me know.
source share