Change string using ref keyword : ref « Language Basics « C# / CSharp Tutorial






using System;

class MainClass
{
  public static void UpperCaseThisString(ref string s)
  {
    s = s.ToUpper();
  }
  public static void Main() 
  {
    string s = "str";
    Console.WriteLine("-> Before: {0}", s);
    UpperCaseThisString(ref s);
    Console.WriteLine("-> After: {0}\n", s);
  }
}
-> Before: str
-> After: STR








1.11.ref
1.11.1.Use ref to pass a value type by reference
1.11.2.Swap two values
1.11.3.Swap two references.
1.11.4.Use out for reference type
1.11.5.Use ref for int value
1.11.6.Use ref for reference type
1.11.7.Change string using ref keyword
1.11.8.Passing Parameters by Value