Last active
August 29, 2015 14:01
-
-
Save Fhernd/ffc8db3242ab12904b64 to your computer and use it in GitHub Desktop.
Demsotracion de los métodos Enumerable.OrderBy, y ArrayList.Sort en C#.
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
// ===++=== | |
// | |
// OrtizOL | |
// | |
// ===--=== | |
/*============================================================ | |
// | |
// Clase: UsoMetodosOrdenamiento.cs | |
// | |
// Propósito: Demostrar el uso de los métodos de | |
// ordenamiento de arreglos y colecciones. | |
// | |
============================================================*/ | |
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace Recetas.Cap02 | |
{ | |
public class UsoMetodosOrdenamiento | |
{ | |
const double CONSTANTE_EULER = 0.577215664901; | |
const double MEDIA_AUREAL = 1.618033988; | |
public static void Main() | |
{ | |
// Creación de un arreglo estándar de double | |
double[] arregloEstandar = {Math.PI, Math.E, CONSTANTE_EULER, MEDIA_AUREAL}; | |
// Creación de un nuevo arreglo ordenado | |
arregloEstandar = Enumerable.OrderBy(arregloEstandar, e => e).ToArray<double>(); | |
// Presentación del contenido ordenado de arregloEstandar | |
Console.WriteLine("Arreglo arregloEstandar ordenado: "); | |
foreach (double d in arregloEstandar) | |
{ | |
Console.WriteLine(d); | |
} | |
// Creación de una lista genérico con tipos string | |
List<string> lista = new List<String>(); | |
lista.Add("OrtizOL"); | |
lista.Add("Experiencias"); | |
lista.Add("Construcción"); | |
lista.Add("Software"); | |
// Presentación de resultados ordenados de la lista | |
Console.WriteLine("\nLista genérica ordenada:"); | |
foreach (string s in Enumerable.OrderBy(lista, e => e)) | |
{ | |
Console.WriteLine(s); | |
} | |
// Cambiamos la expresión lambada para ordener por la longitud de la cadena | |
Console.WriteLine("\nLista 'lista' ordenada por longitud de cadena: "); | |
foreach (string s in Enumerable.OrderBy(lista, e => e.Length)) | |
{ | |
Console.WriteLine(s); | |
} | |
// Creación de una lista ArrayList | |
ArrayList al = new ArrayList(); | |
al.Add("Desarrollador"); | |
al.Add("Programador"); | |
al.Add("Arquitecto"); | |
al.Add("Analista"); | |
// Ordenamiento del ArrayList 'al' | |
al.Sort(); | |
// Presentación contenido ordenado en 'al' | |
Console.WriteLine("\nArrayList 'al' ordenado:"); | |
foreach (string s in al) | |
{ | |
Console.WriteLine(s); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment