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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:21:13+00:00 2026-06-12T10:21:13+00:00

Possible Duplicate: Difference between == operator and Equals() method in C#? Two forms of

  • 0

Possible Duplicate:
Difference between == operator and Equals() method in C#?

Two forms of equality, the first fails, the second succeeds.

(object)"abc" == (object)"abc"
false

((object)"abc").Equals((object)"abc")
true

In the below reference, we see “Equality operators in C# are not polymorphic”

ref: String Equality operator == in c#

btw: still not sure why this is an issue. I thought it might be something like this, but it isn’t because this test succeeds.

    static void Main(string[] args) {
        var o = new classOfT<string>() { val = "abc" };
        Console.WriteLine((object)o.val == "abc");
    }

    public class classOfT<T> {
        public string val { get; set; }
    }

BTW: I DO NOT AGREE WITH THE EXACT DUPLICATE RULING ON THIS QUESTION, BUT HEY.

The Answer states:

… The String class contains both a static bool Equals(string a,
string b) method and a static bool Equals(object a, object b) method.
The difference is that the former is defined within the String class
itself, whilst the latter is inherited from the Object class (which is
the base class of String)

Semantically this makes sense, but does it make sense in the wider context of OO and the C# language?

Why am I bothering with the question? Well, just found a bug, and I’d like to file this in my brain under a rhyme or reason rather than under the “just remember this”, it’s bitten you before category.

Update:

currently thinking about this in terms of working with primitives (from a functional perspective) Vs polymorphism. Since I’ve been doing more and more functional stuff, this is probably why the mother tongue confused me. I’m not done thinking about this yet (no I’m not being pragmatic. I am drawn to language design). Thanks for responding all!

  • 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-12T10:21:15+00:00Added an answer on June 12, 2026 at 10:21 am
    (object)"abc" 
    

    will create an Object reference from the string object. So doing

    (object)"abc" == (object)"abc"
    

    will create two object references, which are not equal.

    However, using the equals method will check to see if the value of the string stored is equal. Again, this is not the default implementation of all objects, but of the String object. For any custom object, you should define your own custom implementation of equals method to achieve this behavior.

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

Sidebar

Related Questions

Possible Duplicate: difference between string object and string literal Let's say I have two
Possible Duplicate: Calculating the Difference Between Two Java Date Instances How do I get
Possible Duplicate: what is the difference between (.) dot operator and (->) arrow in
Possible Duplicate: Difference between declaring variables before or in loop? Consider the two codes
Possible Duplicate: Difference Between Equals and == in which cases equals() works exactly like
Possible Duplicate: php == vs === operator I understand the difference between === ,
Possible Duplicate: What is the difference between the dot (.) operator and -> in
Possible Duplicate: Difference between knockout View Models declared as object literals vs functions I
Possible Duplicate: Difference in SQL Between operator and “>=” & “<=” operator I see
Possible Duplicate: php == vs === operator Is there a difference between !== and

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.