// 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; namespace E { public class Program { private const int N = 20000000; private static readonly Random rng = new Random(); public static void Main(string[] args) { List lst = new List(); for(int i = 0; i < N; i++) lst.Add(rng.NextDouble()); DateTime dt1 = DateTime.Now; int n1; List lst2 = lst.FindAll(delegate(double v) { return v >= 0.5; }); n1 = lst2.Count; DateTime dt2 = DateTime.Now; Console.WriteLine("Find " + n1 + ": " + (dt2-dt1).TotalSeconds); DateTime dt3 = DateTime.Now; int n2; lst.RemoveAll(delegate(double v) { return v < 0.5; }); n2 = lst.Count; DateTime dt4 = DateTime.Now; Console.WriteLine("Remove " + n2 + ": " + (dt4-dt2).TotalSeconds); } } }