Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created April 4, 2019 06:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/df11eb8ed37f11c163dc6bc25b80bbb7 to your computer and use it in GitHub Desktop.
Save parzibyte/df11eb8ed37f11c163dc6bc25b80bbb7 to your computer and use it in GitHub Desktop.
/*
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