Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using System;
using System.Collections.Generic;
using System.Text;
public class MyClass
{
public static void Swap<T> (T a , T b){
T x = a;
a = b;
b = x;
}
public static void RealSwap<T>(ref T a,ref T b){
T x = a;
a = b;
b = x;
}
public static void RunSnippet()
{
System.Text.StringBuilder a,b;
a= new System.Text.StringBuilder("Hello,");
b= new System.Text.StringBuilder(" World!");
Swap<StringBuilder>(a,b); //it doesn't really swapping
RealSwap<StringBuilder>(ref a,ref b);
Console.WriteLine("{0}{1}",b,a);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment