I have a set of model objects that have a public IsVisible
boolean property. All I need to do is find if at least one of the set has that value set to TRUE
. In other words, if I have 10,000 objects but the second one is true
, I don't need to spin through the other 9,998. I already have my answer.
Now I know I could write my own iterating function and break out at the first 'True
' value, but I'm hoping that's something LINQ can do. Actually, it doesn't even need to be LINQ. Any suggestions are welcome.
BTW, the language of choice is C#.
Update:
See my last post here. I've added some test code and timings. Seems LINQ is pretty damn poor performance-wise compared to just doing the test myself. Sure it's easier to write, but in mission-critical timings, I'm no longer sure.
What surprised me though is most of the time I've ran these, enumeration won and by a fair clip, but for some reason, when I wrapped the test in multiple passes, it looks to have switched to indexing with a cached count as being fastest.
I also noticed that if I don't reset everything back to 'false', all the remaining/repeated tests seem to be MUCH faster. Somehow, re-setting everything to FALSE (which was purposely overkill to test exactly this...) changes things.
Interesting. Not sure which way I'm gonna go now. This isn't a mission-critical system so perhaps I'll go for readability, but still. Interesting.