Swap_Values

This method will swap the values of two generic types.

public class GenericMethods 
{
   public static void Swap_Values<T>(
      ref T value1,
      ref T value2)
   {
      T temporary = value1;
      value1 = value2;
      value2 = temporary;
   }
}

int mysize = 5; 
System.Collections.Generic.Stack<double> StackOne;
System.Collections.Generic.Stack<double> StackTwo;

StackOne = new System.Collections.Generic.Stack<double>(mysize);
StackTwo = new System.Collections.Generic.Stack<double>(mysize);

// this swaps the entire collections
GenericMethods.Swap_Values<System.Collections.Generic.Stack<double>>(ref StackOne, ref StackTwo);

double ValueOne = 1.2;
double ValueTwo = 3.4;

// this swaps the individual values
GenericMethods.Swap_Values<double>>(ref ValueOne, ValueTwo);


© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext