Reference, output and value parameters.

   
 




using System;

class ReferenceAndOutputParameters
{
   public void aMethod()
   {
      int y = 5; 
      int z; 

      Console.WriteLine( "Original value of y: {0}", y );
      Console.WriteLine( "Original value of z: uninitialized
" );

      SquareRef( ref y );  
      SquareOut( out z );  

      Console.WriteLine( "Value of y after SquareRef: {0}", y );
      Console.WriteLine( "Value of z after SquareOut: {0}
", z );

      Square( y );
      Square( z );

      Console.WriteLine( "Value of y after Square: {0}", y );
      Console.WriteLine( "Value of z after Square: {0}", z );
   } 
   void SquareRef( ref int x )
   {
      x = x * x; 
   } 
   void SquareOut( out int x )
   {
      x = 6; 
      x = x * x; 
   } 
   void Square( int x )
   {
      x = x * x;
   }
} 
class ReferenceAndOutputParamtersTest
{
   static void Main( string[] args )
   {
      ReferenceAndOutputParameters test = new ReferenceAndOutputParameters();
      test.aMethod();
   }
}