c# - Do Enumerable.FirstOrDefault() stop when it finds item? -
i tried searching on msdn, , on web not find answer.
say have collection in firstordefault()
. let finds item. stop , returns item or continue searching , hampers performance?
if still vague on this, source code in .net framework implemented here:
public static tsource firstordefault<tsource>(this ienumerable<tsource> source) { if (source == null) throw error.argumentnull("source"); ilist<tsource> list = source ilist<tsource>; if (list != null) { if (list.count > 0) return list[0]; } else { using (ienumerator<tsource> e = source.getenumerator()) { if (e.movenext()) return e.current; } } return default(tsource); } public static tsource firstordefault<tsource>(this ienumerable<tsource>source, func<tsource, bool> predicate) { if (source == null) throw error.argumentnull("source"); if (predicate == null) throw error.argumentnull("predicate"); foreach (tsource element in source) { if (predicate(element)) return element; } return default(tsource); }
apparently, stop if founded
Comments
Post a Comment