Interlocked.Add : Interlocked « System.Threading « C# / C Sharp by API






Interlocked.Add

  

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.Add(ref firstInt, secondInt);

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

    }
}

   
    
  








Related examples in the same category

1.Interlocked.CompareExchange
2.Interlocked.Decrement
3.Interlocked.Exchange
4.Interlocked.Increment