c# - Using LINQ First() method shows "Possible multiple iteration of IEnumerable" warning by Resharper -
c# - Using LINQ First() method shows "Possible multiple iteration of IEnumerable" warning by Resharper -
i have code this:
person firstperson = personsenumerable.first();
, personsenumerable
ienumerable<person>
now, resharper underlines personsenumerable variable , says "possible iteration of ienumerable". understand warning means other questions here on so, i'm wondering why it's showing in example? think first() returns first element , there's no need iterate collection @ ?
is 'general' warning message not applicable in case (and can ignore it) or don't understand how first() works ?
yes, returns first element still creates enumerator first element.you add together toarray
or tolist
after where
prevent this. if want first element, utilize overloaded version of first
takes func
delegate , can remove where
.
c# linq resharper
Comments
Post a Comment