-
-
Save parzibyte/2f80471a92bab1304d2c804962301c89 to your computer and use it in GitHub Desktop.
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
using System; | |
class MainClass { | |
public static void Main (string[] args) { | |
// Arreglo desordenado | |
string[] canciones = { | |
"Drive in saturday", | |
"Ziggy stardust", | |
"Let's spend the night together", | |
"Hang on to yourself", | |
"Ashes to ashes", | |
"Moonage daydream", | |
}; | |
// Crear un comparador que ordena de manera ascendente, | |
// usando CompareTo en las cadenas, lo cual compara alfabéticamente | |
Comparison<string> comparador = new Comparison<string>((cadena1, cadena2) => cadena1.CompareTo(cadena2)); | |
// Llamar a Array.Sort, pasando el arreglo a ordenar y el comparador | |
Array.Sort<string>(canciones, comparador); | |
// Ahora simplemente imprimimos | |
foreach(string cancion in canciones){ | |
Console.WriteLine(cancion); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment