// 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; using System.Threading; namespace Modern3 { public class Data { public DateTime Created { get; set; } public int Counted { get; set; } public Data(int c) { Created = DateTime.Now; Counted = c; } public override string ToString() { return string.Format("[{0}: {1}]", Created, Counted); } } public class ExtData : Data { public bool Verified { get; set; } public ExtData(int c, bool v) : base(c) { Verified = v; } public override string ToString() { return string.Format("[{0}: {1} ({2})]", Created, Counted, Verified ? "Verified" : "Not verified"); } } public class Program { public static void Dump(string lbl, IEnumerable lstd) { Console.WriteLine(lbl); foreach (Data d in lstd) { Console.WriteLine(d); } } public static void Main(string[] args) { Console.WriteLine("C#"); List alld = new List(); alld.Add(new ExtData(37, true)); Thread.Sleep(1000); alld.Add(new ExtData(32, true)); Thread.Sleep(1000); alld.Add(new ExtData(19, true)); Thread.Sleep(1000); alld.Add(new ExtData(50, false)); Dump("All:", alld); Dump("Counted < 30:", alld.Where(d => d.Counted < 30)); Dump("Verified = false:", alld.Where(d => !d.Verified)); Console.ReadKey(); } } }