Swap two parameter using ref - CSharp Custom Type

CSharp examples for Custom Type:Method Parameter

Description

Swap two parameter using ref

Demo Code

using System;/*from   ww  w.  java 2s. c  o m*/
class Swapper
{
   public static void Main()
   {
      int myValue = 10;
      int yourValue = 20;
      Swap(ref myValue, ref yourValue);
      Console.WriteLine("My value: {0}   Your value: {1}", myValue, yourValue);
   }
   public static void Swap(ref int a, ref int b)
   {
      int temp;
      temp = a;
      a = b;
      b = temp;
   }
}

Result


Related Tutorials