Created
March 27, 2016 16:50
-
-
Save Fhernd/6d6c945ce85b9bdfabf6 to your computer and use it in GitHub Desktop.
Demostración de ordenamiento de diccionario por valor 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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace Articulo.Pregunta.P1920 | |
{ | |
public class OrdenamientoDiccionarioValor | |
{ | |
public static void Main() | |
{ | |
// Definición objeto Dictionary: | |
Dictionary<string, string> dicNumeros = new Dictionary<string, string>(); | |
// Agregación de elementos: | |
dicNumeros.Add("2", "Dos"); | |
dicNumeros.Add("5", "Cinco"); | |
dicNumeros.Add("1", "Uno"); | |
dicNumeros.Add("3", "Tres"); | |
dicNumeros.Add("4", "Cuatro"); | |
var dicNumerosOrdenadosPorValor = from dicElemento in dicNumeros orderby dicElemento.Value | |
ascending select dicElemento; | |
// Iteración por elementos del diccionario ordenados | |
// alfabéticamente por valor: | |
foreach(object elemento in dicNumerosOrdenadosPorValor) | |
{ | |
Console.WriteLine (elemento); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment