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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:48:41+00:00 2026-06-02T00:48:41+00:00

I have these statements and their’ results are near them. string a = abc;

  • 0

I have these statements and their’ results are near them.

string a = "abc";
string b = "abc";

Console.Writeline(a == b); //true

object x = a;
object y = b;

Console.Writeline(x == y); // true

string c = new string(new char[] {'a','b','c'});
string d = new string(new char[] {'a','b','c'});

Console.Writeline(c == d); // true

object k = c;
object m = d;

Console.Writeline(k.Equals(m)) //true

Console.Writeline(k == m); // false

Why the last equality gives me false ?

The question is why ( x == y ) is true ( k == m ) is false

  • 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-02T00:48:43+00:00Added an answer on June 2, 2026 at 12:48 am
    string a = "abc"; 
    string b = "abc"; 
    
    Console.Writeline(a == b); //true 
    

    String references are the same for the same string due to String Interning

    object x = a; 
    object y = b; 
    
    Console.Writeline(x == y); // true 
    

    Because the references are the same, two objects created from the same reference are also the same.

    string c = new string(new char[] {'a','b','c'}); 
    string d = new string(new char[] {'a','b','c'}); 
    

    Here you create two NEW arrays of characters, these references are different.

    Console.Writeline(c == d); // true 
    

    Strings have overloaded == to compare by value.

    object k = c; 
    object m = d; 
    

    Since the previous references are different, these objects are different.

    Console.Writeline(k.Equals(m)) //true 
    

    .Equals uses the overloaded String equals method, which again compare by value

    Console.Writeline(k == m); // false 
    

    Here we check to see if the two references are the same… they are not

    The key is figuring out when an equality is comparing references or values.

    Objects, unless otherwise overloaded, compare references.

    Structs, unless otherwise overloaded, compare values.

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

Sidebar

Related Questions

I have these three lists with the same number of elements List<String>competitoinsIDs = new
I have these long statements that I will refer to as x,y etc. here.
I have these 2 statements: $pow= mysql_query(select options.label from options where userid='1'); and: $sql=(SELECT
I have these two statements : printf(%u,a+1); and printf(%u,(int *)a+1); Actually I was working
I have these 3 tables: and I'm using this code to join them together
I have these variables: boost::regex re //regular expression to use std::string stringToChange //replace this
I have a SQL statement which returns a number of rows and these are
I have these tables: comments uid id pid pages pid user users id rank
I have a persistent object with 7 pertinent fields. The fields can hold the
I have two separate SELECT statements which are both GROUP-BY'd separately e.g.: SELECT x,

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.