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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:29:06+00:00 2026-05-27T20:29:06+00:00

Class is a reference types while Struct is a value type. This means that

  • 0

Class is a reference types while Struct is a value type.

This means that I do not need to explicitly specify ref for every parameter which is a type of class.

My Question is,

Why do we have to specify a ref keyword for a string type which is basically a type of class ?

Please find the example below

public partial class StringManupulation : Form
{
    public StringManupulation()
    {
        InitializeComponent();

        String value = "Hello ";

        Concatenate( value );
        MessageBox.Show( value );

        Concatenate( ref value );
        MessageBox.Show( value );
    }

    /// <summary>
    /// Does not work
    /// </summary>
    /// <param name="value"></param>
    public void Concatenate( String value )
    {
        value = string.Concat( value, "StackOverflow" );
    }

    /// <summary>
    /// Works! 
    /// </summary>
    /// <param name="value"></param>
    public void Concatenate( ref String value )
    {
        value = string.Concat( value, "StackOverflow" );
    }
 }
  • 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-27T20:29:06+00:00Added an answer on May 27, 2026 at 8:29 pm

    System.String is immutable – That means you cannot change the content of string once it is assigned. You may try System.Text.StringBuilder (mutable object) instead of System.String class.

    static void ParamTest(System.Text.StringBuilder  paramSb)
    {
      paramSb.Append("World");
    }
    
    static void Main()
    {
      System.Text.StringBuilder sb = new StringBuilder();
      sb.Append("Hello");
    
      ParamTest(sb);
      Console.WriteLine(sb);
    }
    

    Have a look at Strings in C# and .NET and article – chapter from C# in Depth.

    Quote to Jon Skeet

    It is a reference type?

    It’s a common misconception that string is a
    value type. That’s because its immutability (see next point) makes it
    act sort of like a value type. It actually acts like a normal
    reference type. See my articles on parameter passing and memory for
    more details of the differences between value types and reference
    types.

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

Sidebar

Related Questions

the basic idea is that you have some class that has a reference type
What is the definition of a value class and reference class in C#? How
Given: struct Field { template<class T> T Value() const { // ??? } template<class
Back to the basics... For reference types, one can do this: SomeType someObject =
If have a union that currently foresees some simple data types: union Value {
While reading "C# in Depth" I was going through the section titled "Reference types
In the NSObject Class Reference they talk about an isa instance variable which is
What is the use of creating base class object using child class reference in
How can I create an instance of an object using a class reference, and
In PHP, how can a class reference its own name? For example, what would

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.