Advertisement
Fhernd

OrdenamientoDiccionarioValor.cs

Mar 27th, 2016
8,002
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.07 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Articulo.Pregunta.P1920
  6. {
  7.     public class OrdenamientoDiccionarioValor
  8.     {
  9.         public static void Main()
  10.         {
  11.             // Definición objeto Dictionary:
  12.             Dictionary<string, string> dicNumeros = new Dictionary<string, string>();
  13.            
  14.             // Agregación de elementos:
  15.             dicNumeros.Add("2", "Dos");
  16.             dicNumeros.Add("5", "Cinco");
  17.             dicNumeros.Add("1", "Uno");
  18.             dicNumeros.Add("3", "Tres");
  19.             dicNumeros.Add("4", "Cuatro");
  20.            
  21.             var dicNumerosOrdenadosPorValor = from dicElemento in dicNumeros orderby dicElemento.Value
  22.                                                 ascending select dicElemento;
  23.            
  24.             // Iteración por elementos del diccionario ordenados
  25.             // alfabéticamente por valor:
  26.             foreach(object elemento in dicNumerosOrdenadosPorValor)
  27.             {
  28.                 Console.WriteLine (elemento);
  29.             }
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement