Demonstrate pass-by-reference semantics. - CSharp Custom Type

CSharp examples for Custom Type:Method Parameter

Description

Demonstrate pass-by-reference semantics.

Demo Code

using System;/*  w  w  w. ja  v  a 2s  . c  om*/
public class Program
{
   public static void Update(ref int i, out double d)
   {
      i = 10;
      d = 20.0;
   }
   public static void Main(string[] args)
   {
      int i = 1;
      double d;
      Console.WriteLine("Before the call to Update(ref int, out double):");
      Console.WriteLine("i = " + i + ", d is not initialized");
      Update(ref i, out d);
      Console.WriteLine("After the call to Update(ref int, out double):");
      Console.WriteLine("i = " + i + ", d = " + d);
   }
}

Result


Related Tutorials