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

  • Home
  • SEARCH
  • 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 8914383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:42:27+00:00 2026-06-15T04:42:27+00:00

I was reviewing some code, and I found something that looked like this: public

  • 0

I was reviewing some code, and I found something that looked like this:

public class MyClass
{
    public bool IsEditable { get; set; }

    public void HandleInput()
    {
        if (IsEditable.Equals(false))
        {
            //do stuff
        }
    }
}

As far as I know, (IsEditable.Equals(false)) is identical to (IsEditable == false) (and also the same as (!IsEditable)).

Besides personal preference, is there any difference at all between .Equals() and ==, specifically when used to compare bools?

  • 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-15T04:42:28+00:00Added an answer on June 15, 2026 at 4:42 am

    The Equals way appears to be significantly slower – roughly 2.7 times in debug mode, and more than seven times in release mode.

    Here is my quick and dirty benchmark:

    public static void Main() {
        bool a = bool.Parse("false");
        bool b = bool.Parse("true");
        bool c = bool.Parse("true");
        var sw = new Stopwatch();
        const int Max = 1000000000;
        int count = 0;
        sw.Start();
        // The loop will increment count Max times; let's measure how long it takes
        for (int i = 0; i != Max; i++) {
            count++;
        }
        sw.Stop();
        var baseTime = sw.ElapsedMilliseconds;
        sw.Start();
        count = 0;
        for (int i = 0; i != Max; i++) {
            if (a.Equals(c)) count++;
            if (b.Equals(c)) count++;
        }
        sw.Stop();
        Console.WriteLine(sw.ElapsedMilliseconds - baseTime);
        sw.Reset();
        count = 0;
        sw.Start();
        for (int i = 0; i != Max; i++) {
            if (a==c) count++;
            if (b==c) count++;
        }
        sw.Stop();
        Console.WriteLine(sw.ElapsedMilliseconds - baseTime);
        sw.Reset();
        count = 0;
        sw.Start();
        for (int i = 0; i != Max; i++) {
            if (!a) count++;
            if (!b) count++;
        }
        sw.Stop();
        Console.WriteLine(sw.ElapsedMilliseconds - baseTime);
    }
    

    Running this produces the following results:

    In debug mode

    8959
    2950
    1874
    

    In release mode

    5348
    751
    7
    

    Equals appears to be the slowest. There appears to be little difference between == and !=. However, if (!boolExpr) appears to be the clear winner.

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

Sidebar

Related Questions

I'm reviewing some team code and I found something like this : MyObj obj
I have been reviewing some code that looks like this: class A; // defined
I'm reviewing some code I've inherited, and I found a line like this: And
I'm reviewing some legacy code and I've found a bug that causes the response
Reviewing some code that contains a bunch indirectly nested transactionscopes. I would like to
I was reviewing some code and I came across this: public static doSomething(String myString,
I'm reviewing some code and I'm seeing a lot of this: class Foo {
Whilst reviewing some Qt C++ code I came across this: class Foo { Q_OBJECT
I'm reviewing some old python code and came accross this 'pattern' frequently: class Foo(object):
I am reviewing some C code, and found a header file full of defines

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.