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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:20:00+00:00 2026-05-29T11:20:00+00:00

String object behaves like a Value type when using == and != operators which

  • 0

String object behaves like a Value type when using == and != operators which means the actual object rather than the reference is checked.

What about parameter passing, assignments and copying?

String Parameter Passing:
When a reference type is passed to a method, its reference is copied but the underlying object stays the same.

Would this also be true about String type in C#? I mean would there be 2 pointers (messageVar and messageParam) pointing to the same object in the below code:

public static void main()
{
   string messageVar = "C#";
   Test(messageVar);

   // what about in assignement?
   string messageVar2 = messageVar;
}
public void Test(string messageParam)
{
// logic
}

What about when it’s assigned to a variable? I’d guess, the reference would be copied only and the actual object stays the same cached in the String Intern Pool. Not sure.

Would messageVar2 also refers to the same object?

Thanks,

  • 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-29T11:20:01+00:00Added an answer on May 29, 2026 at 11:20 am

    Yes, you are correct only references are copied, the object instance referenced is one and the same.

    You can easily verify this using Object.ReferenceEquals() to test if two references point to the same object instance – I modified your example a bit to show this:

    static string messageVar = "C#";
    public static void Main(string[] args)
    {
        bool isSame = Test(messageVar); //true
    
        // what about in assignement?
        string messageVar2 = messageVar;
        isSame = Object.ReferenceEquals(messageVar2, messageVar);//also true
    }
    
    public static bool Test(string messageParam)
    {
        // logic
        bool isSame = Object.ReferenceEquals(messageParam, messageVar);
        return isSame;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for a piece of code which behaves a bit like a singleton
Is it possible to create a NumPy object that behaves very much like a
I have a string object with multiple characters and even special characters I am
I have a C# string object that contains the code of a generic method,
I have a String Object in format yyyyMMdd .Is there a simple way to
My co-worker is filling a System::String object with double-byte characters from an unmanaged library
Why does C#.Net allow the declaration of the string object to be case-insensitive? String
I want to assign a class attribute via a string object - but how?
i try to put a lock to a static string object to access to
When you use the Trim() method on a string object, you can pass an

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.