Implications of passing by reference - CSharp Custom Type

CSharp examples for Custom Type:Method Parameter

Introduction

In the following example, the variables x and y represent the same instance:

Demo Code

using System;//from ww  w  . ja  v  a 2s.c om
class Test
{
   static int x;
   static void Main() { Foo (out x); }
   static void Foo (out int y)
   {
      Console.WriteLine (x);                // x is 0
      y = 1;                                // Mutate y
      Console.WriteLine (x);                // x is 1
   }
}

Result


Related Tutorials