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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:29:05+00:00 2026-05-12T17:29:05+00:00

I have being studying (newbie) .NET and I got some doubts. Reading from a

  • 0

I have being studying (newbie) .NET and I got some doubts.

Reading from a book examples I learnt that String are object then Reference Type.

So, I did this test and the result was different what I expected:

I’m really curious, is this an exception because “string” are special types?

class Program
{
    static void Main(string[] args)
    {
        SByte a = 0;
        Byte b = 0;
        Int16 c = 0;
        Int32 d = 0;
        Int64 e = 0;
        string s = "";
        Exception ex = new Exception();

        object[] types = { a, b, c, d, e, s, ex };

        // C#
        foreach (object o in types)
        {
            string type;
            if (o.GetType().IsValueType)
                type = "Value type";
            else
                type = "Reference Type";
            Console.WriteLine("{0}: {1}", o.GetType(), type);
        }

        // Test if change
        string str = "I'll never will change!";

        Program.changeMe(str);

        Console.WriteLine(str);
    }

    public static string changeMe(string param)
    {
        param = "I have changed you!!!";

        return ""; // no return for test
    }
}

Output:

System.SByte: Value type
System.Byte: Value type
System.Int16: Value type
System.Int32: Value type
System.Int64: Value type
System.String: Reference Type
System.Exception: Reference Type
I'll never will change!
  • 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-12T17:29:06+00:00Added an answer on May 12, 2026 at 5:29 pm

    String is indeed a reference type. However, when your Main method calls changeMe(str), .NET passes a copy of the reference to str to changeMe in the param argument. changeMe then modifies this copy to refer to “I have changed you!!!”, but the original str reference still points to “I will never change”.

    Being a reference type means that if you changed the state of the passed string, the caller would see those changes. (You can’t do this to a string because strings are immutable, but you can do it to other reference types e.g. Control.) But reassigning a parameter doesn’t change the value the caller passed in that parameter, even if that value is a reference.

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

Sidebar

Related Questions

I have an exception being thrown from a C# method, that takes a generic
I have a Form being launched from another form on a different thread. Most
I have a List being returned from a daoTemplate.query() call, using a rowMapper .
I have a datalist being generated with ASP, but unfortunately the jQuery script that
I have been studying .NET 4.0 Code Contracts and looking on stackoverflow as well
Problem I'm fairly new to design patterns, and have been studying the book, Head
I have a UDP server that I have being trying to send structures using
I'm relatively new to .NET and have being using Linq2Sql for a almost a
I noticed that i have not being getting traffic via google organic searches. I
I have being messing about with DOM XPath stuff all day - reading around

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.