Exchange

image_pdfimage_print
   
 

using System;
using System.Threading;

class MainClass
{
    public static void Main()
    {
        int firstInt = 25;
        int secondInt = 80;

        Console.WriteLine("firstInt initial value = {0}", firstInt);
        Console.WriteLine("secondInt initial value = {0}", secondInt);

        Interlocked.Exchange(ref secondInt, firstInt);

        Console.WriteLine("firstInt after Exchange = {0}", firstInt);
        Console.WriteLine("secondInt after Exchange = {0}", secondInt);

    }
}