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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:27:22+00:00 2026-05-13T16:27:22+00:00

a) string s = value; string s1 = value; Do s and s1 reference

  • 0

a)

        string s  = "value";
        string s1 = "value";

Do s and s1 reference variables point to same string object ( I’m assuming this due to the fact that strings are immutable )?

b) I realize equality operators ( ==, > etc ) have been redefined to compare the values of string objects, but is the same true when comparing two strings using static methods Object.Equals() and Object.ReferenceEquals()?

thanx

  • 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-13T16:27:23+00:00Added an answer on May 13, 2026 at 4:27 pm

    No, not all strings with the same value are the same object reference.

    Strings generated by the compiler will all be Interned and be the same reference. Strings generated at runtime are not interned by default and will be different references.

    var s1 = "abc";
    var s2 = "abc";
    var s3 = String.Join("", new[] {"a", "b", "c"});
    var s4 = string.Intern(s3); 
    Console.WriteLine(ReferenceEquals(s1, s2)); // Returns True
    Console.WriteLine(ReferenceEquals(s1, s3)); // Returns False
    Console.WriteLine(s1 == s3); // Returns True
    Console.WriteLine(ReferenceEquals(s1, s4)); // Returns True
    

    Note the line above where you can force a string to be interned using String.Intern(string) which then allows you to use object equality instead of string equality for some checks, which is much faster. One example where this is very commonly used is inside the generated XML serializer code along with the name table.

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

Sidebar

Related Questions

One would expect that even though strings are immutable, value-equality and reference-equality would not
Is string a value type or a reference type? I just can't find a
String s = hello; String backup_of_s = s; s = bye; At this point,
I was just reading this site which states: Although string is a reference type,
I understand that in Javascript, variables are always assigned by reference which means that
When try to convert string value in date-time format some time string variable comes
I have a string value coming from a label in the .aspx page as
I have string value and Type of some variable (For example int and 32
I've got a string value of the form 10123X123456 where 10 is the year,
How to read query string value via managed bean in jsf1.1

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.