TabCollection.Where(s => s.TabHeader == h).FirstOrDefault()
This creates WhereIterator
and returns it. Then you starting iteration and return first element of it. That looks like
var iterator = new WhereEnumerableIterator<TSource>(TabCollection, predicate);
using (IEnumerator<TSource> enumerator = iterator.GetEnumerator())
{
if (enumerator.MoveNext())
return enumerator.Current;
}
return default(TSource);
Second one does not create iterator - it simply enumerates over source:
TabCollection.FirstOrDefault(s => s.TabHeader == h);
Same as
foreach (TSource local in TabCollection)
{
if (predicate(local))
return local;
}
return default(TSource);
So, second option is slightly more efficient.