Do all the things like ++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatarSign Up
datanerd018dWhy not? :S
Count() will evaluate the condition on all elements in the list. Now suppose that list to be extremely huge, and the condition's evaluation to be relatively complex.
In this particular example it would be way more efficient to write for example:
var element = HugeList.FirstOrDefault(Condition);
if(element != null)
I'm just gonna say it: Don't use these stupid functional list manipulation methods full stop if you care about performance
@12bitfloat That’s the most retarded comment I’ve read on devrant in a very long time.
Most of the time these functions implement very good algos. Keep writing your bubble sort manually.
I can agree, that you need to understand HOW they work in order to avoid triple (or even 10x times) iteration of the initial list. But in 95% of cases even “badly” written statement will be faster than half-baked “custom” solution. And there are special cases when Database is involved.
It depends. I like using “map” and “filter” in JS. And no, I don't like 100000 libs in front end
But let’s just see what happens if I slightly edit the original code. I only added toArray.
var filteredList = hugeList.Where(x => x.Number == 1).ToArray();
Result ? The list was enumerated only once. (note : items are not cloned with ToArray, so memory overhead is very small).
Edit : FirstOrDefault solution is still better