Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1084733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:36:01+00:00 2026-05-16T22:36:01+00:00

I have a set of model objects that have a public IsVisible boolean property.

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T22:36:01+00:00Added an answer on May 16, 2026 at 10:36 pm

    The method you’re looking for is Enumerable.Any.

    bool anyObjectsVisible = myObjects.Any(myObject => myObject.IsVisible);
    

    This has the exact short-circuiting semantics you are looking for; the sample code is similar to:

    static bool AreAnyObjectsVisible(IEnumerable<MyObject> myObjects)
    {
        foreach (var myObject in myObjects)
        {
            if (myObject.IsVisible) return true;
        }
    
        return false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As described in another question , I have a set of Model objects and
I have a modeled a set of objects that correspond with some real world
I have the whole MVC-Model set up and use HTML views as templates. But
I have a set of data that models a hierarchy of categories. A root
I have set up a Django application that uses images. I think I have
Imagine I have a list of objects that implement an interface called ISummary The
Say you have a one to one relationship in your entity model. The code
I'm working on a blog application in Django. Naturally, I have models set up
I have authentication mode set to forms in my asp.net web.config but am still
We have set up a system where notifications get sent to a user with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.