Swaps the values. - CSharp System

CSharp examples for System:Object

Description

Swaps the values.

Demo Code

// This file is subject to the terms and conditions defined in
using System.Windows.Threading;
using System.Windows.Shapes;
using System.Windows.Media;
using System.Windows.Input;
using System.Windows.Controls;
using System.Windows;
using System.Globalization;
using System;/*from ww  w.  j av a 2  s.  c  o m*/

public class Main{
        /// <summary>
        /// Swaps the values.
        /// </summary>
        /// <typeparam name="T">The type of the objects to swap.</typeparam>
        /// <param name="a">First value to swap.</param>
        /// <param name="b">Second value to swap.</param>
        public static void Swap<T>(ref T a, ref T b)
        {
            var dummy = a;
            a = b;
            b = dummy;
        }
}

Related Tutorials