Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created September 23, 2013 23:27
Show Gist options
  • Save Fhernd/6678393 to your computer and use it in GitHub Desktop.
Save Fhernd/6678393 to your computer and use it in GitHub Desktop.
Uso interesante del modificador ref en el diseño de algoritmos de intercambio (swap).
class PruebaSwap
{
static void Swap(ref string a, ref string b)
{
string temp = a;
a = b;
b = temp;
}
static void Main()
{
string x = "Juan";
string y = "Oliva";
Swap(ref x, ref y);
Console.WriteLine(x); // Oliva
Console.WriteLine(y); // Juan
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment