Use ref to pass an int value type by reference : Parameter Reference « Language Basics « C# / CSharp Tutorial






using System; 
 
class RefTest { 
  /* This method changes its argument. 
     Notice the use of ref. */ 
  public void sqr(ref int i) { 
    i = i * i; 
  } 
} 
 
class MainClass { 
  public static void Main() { 
    RefTest ob = new RefTest(); 
 
    int a = 10; 
 
    Console.WriteLine("a before call: " + a); 
 
    ob.sqr(ref a); // notice the use of ref 
 
    Console.WriteLine("a after call: " + a); 
  } 
}
a before call: 10
a after call: 100








1.13.Parameter Reference
1.13.1.Pass references to methods
1.13.2.Objects are passed by reference.
1.13.3.Use ref to pass an int value type by reference
1.13.4.Passing value types by reference