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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:13:45+00:00 2026-05-28T14:13:45+00:00

Assuming I am designing a collection of objects for use by others and assuming

  • 0

Assuming I am designing a collection of objects for use by others and assuming I have read and understood (huh?) most threads about the differences between operator== and Equals(), WHY should I ever implement operator==?

Stealing an example from this thread, using it can be quite error prone:

object x = "hello";
object y = 'h' + "ello"; // ensure it's a different reference
(x == y); // evaluates to FALSE
string x = "hello";
string y = 'h' + "ello"; // ensure it's a different reference
(x == y); // evaluates to TRUE

So, can I tell my users to just use Equals() and ReferenceEquals() and that’s it? What am I missing there?

  • Are there maybe pieces of the standard code base that use == and there is no way around it?

  • Is the == performance a lot better in some important cases? (well, ok, Equals is a virtual so it’s gonna be a bit slower all the time, but i cannot see any use case where this actually becomes a bottleneck)

  • something else?
  • 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-28T14:13:46+00:00Added an answer on May 28, 2026 at 2:13 pm

    You can tell your users just to use Equals… but I for one find it very handy that various types (including String) overload ==. Yes, you need to be aware of the way that overload resolution works, but for most experienced developers I suspect that isn’t a problem most of the time, whereas:

    if (Equals(x, y))
    

    ends up looking nastier than

    if (x == y)
    

    in my view. Note that these are both different to

    if (x.Equals(y))
    

    which will blow up if x is null, of course…

    If you prefer not to overload == then it’s not like anything will fail – you just may get disgruntled users.

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

Sidebar

Related Questions

Assuming that best practices have been followed when designing a new database, how does
Assuming I have a collection in MongoDB with 5000 records, each containing something similar
Assuming you have a business that rents movie and you were designing a schema
Assuming I have a numerical string: var foo = 0; Assume I want to
Assuming that I have this: enum { A = 0x2E, B = 0x23, C
Assuming all my Gradle plugin user going to have a MYAPP_HOME sys variable set
Assuming I have a ASP.NET MVC 3 application that runs in a web farm
assuming I have the following array: views = [ { :user_id => 1, :viewed_at
Assuming i have a post model with created_at, title, and id. How can i
I have no experience with Wordpress template designing so far, and this will be

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.