Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created March 27, 2016 16:50
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 Fhernd/6d6c945ce85b9bdfabf6 to your computer and use it in GitHub Desktop.
Save Fhernd/6d6c945ce85b9bdfabf6 to your computer and use it in GitHub Desktop.
Demostración de ordenamiento de diccionario por valor en C#.
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