-
-
Save parzibyte/df11eb8ed37f11c163dc6bc25b80bbb7 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
/* | |
Ordenar arreglo de tipo int | |
de manera descendente en C# | |
*/ | |
using System; | |
class MainClass { | |
public static void Main (string[] args) { | |
// Arreglo desordenado | |
int[] numeros = {50, 8, 96, 200, 13, 123, 1, 1, 23, 3, 54, 51}; | |
// Crear un comparador que ordena de manera descendente, | |
// solo intercambiamos el orden de comparación | |
Comparison<int> comparador = new Comparison<int>((numero1, numero2) => numero2.CompareTo(numero1)); | |
// Llamar a Array.Sort, pasando el arreglo a ordenar y el comparador | |
Array.Sort<int>(numeros, comparador); | |
// Ahora simplemente imprimimos | |
foreach(int numero in numeros){ | |
Console.WriteLine(numero); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment