// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Collections.Generic; using System.Linq; namespace E { public class Program { public static void Main(string[] args) { Dictionary d1 = new Dictionary(); d1.Add("BSOne", "1"); d1.Add("BSTwo", "2"); d1.Add("PLOne", "11"); d1.Add("PLTwo", "22"); foreach(KeyValuePair kvp in d1) { Console.WriteLine(kvp.Key + " = " + kvp.Value); } Dictionary d2 = d1.Where(kvp => kvp.Key.StartsWith("BS")).ToDictionary(kvp => kvp.Key, kvp => kvp.Value); foreach(KeyValuePair kvp in d2) { Console.WriteLine(kvp.Key + " = " + kvp.Value); } } } }