Created
September 23, 2013 23:27
-
-
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).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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