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 7989565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:47:15+00:00 2026-06-04T12:47:15+00:00

I have a list: List<MyClass> MyList = new List<MyClass>(); . MyClass has methods SetBool

  • 0

I have a list: List<MyClass> MyList = new List<MyClass>();.

MyClass has methods SetBool and IsTrue. I have to set every object of this list to false (obj.SetBool(false)).

There are 2 possible ways:

First:

foreach (MyClass obj in MyList)
{
    obj.SetBool(false)
}

Second:

List<MyClass> MyList2 = MyList.Where(c => c.IsTrue()).ToList();

foreach (MyClass obj in MyList2)
{
    obj.SetBool(false)
}

If I use first one it may be slow because it changes every element. The second way can be slow too, because it has to find objects first.

So my question is:
Which one will be faster (I may have very large number of elements in list) and why?

  • 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-06-04T12:47:17+00:00Added an answer on June 4, 2026 at 12:47 pm

    Fastest would be the combination:

    foreach (MyClass obj in MyList)
    {
        if (obj.IsTrue())
            obj.SetBool(false)
    }
    

    But the difference with your first version will only be meaningful when SetBool() does some extensive validations or computation, and is much more expensive than Istrue().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a DataGridView with the DataSource set to List<myClass> However, the new row
I have a List<MyClass> The class is like this: private class MyClass { public
I have a list of class items List<MyClass> I have a seperate object that
This is a long shot, I know... Let's say I have a collection List<MyClass>
I have a base class like this: package MyClass; use vars qw/$ME list of
Let's say I have: class myClass std::list<myClass> myList where myClass does not define the
I have a java list List<myclass> myList = myClass.selectFromDB(where clause); //myClass.selectFromDB returns a list
I have a one method like this: private void myMethod(List<?> myLists) { for (Object
I have a class like this: public class myClass { public List<myOtherClass> anewlist =
I have a class MyClass containing a private List<MySecondClass> myList . The list is

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.