Use LINQ with Dictionary : select « LINQ « C# / CSharp Tutorial






using System;
using System.Collections.Generic;
using System.Linq;

static class TestDictionary {
    static void Main() {
        Dictionary<int, string> frenchNumbers;
        frenchNumbers = new Dictionary<int, string>();
        frenchNumbers.Add(0, "zero");
        frenchNumbers.Add(1, "one");
        frenchNumbers.Add(2, "two");
        frenchNumbers.Add(3, "three");
        frenchNumbers.Add(4, "four");

        var evenFrenchNumbers =
          from entry in frenchNumbers
          where (entry.Key % 2) == 0
          select entry.Value;
    }
}








22.63.select
22.63.1.Query Reuse
22.63.2.Select array item by type
22.63.3.Use LINQ with Dictionary
22.63.4.Use LINQ to query characters in a string
22.63.5.Transformation: link two array.
22.63.6.Select with Anonymous Types: prints uppercase and lowercase versions of each string in an input array
22.63.7.Select with Anonymous Types: iterates over each element to print the element's name
22.63.8.Select with Anonymous Types: prints the name of every product in the product list along with the category of the product and its unit price
22.63.9.Using select to create a sequence of each product name.
22.63.10.Converting an Array of Strings to Integers
22.63.11.Converting an Array of Strings to Integers and Sorting It
22.63.12.Query with Intentional Exception Deferred Until Enumeration
22.63.13.Demonstrating the Query Results Changing Between Enumerations
22.63.14.Returning a List
22.63.15.Select Distinct
22.63.16.Select all from a List
22.63.17.Select only pet name
22.63.18.Select sum value
22.63.19.Delegate targets
22.63.20.Adding new line character to selected value