// 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.Linq; using System.Collections.Generic; using System.Threading; namespace E { public class DelayedContainer { private IDictionary data = new Dictionary(); public void Add(T o) { if(data.ContainsKey(o)) data[o] = DateTime.Now; else data.Add(o, DateTime.Now); } public IList GetList() { DateTime cut = DateTime.Now.AddSeconds(-3); return data.Where(e => e.Value < cut).Select(e => e.Key).ToList(); } } public class Program { public static void Main(string[] args) { DelayedContainer lst = new DelayedContainer(); for(int i = 1; i <= 10; i++) { lst.Add((i-1)%5+1); Console.WriteLine("Adding " + ((i-1)%5+1)); foreach(int v in lst.GetList()) Console.Write(" " + v); Console.WriteLine(); Thread.Sleep(1000); } Thread.Sleep(3000); Console.WriteLine("Done"); foreach(int v in lst.GetList()) Console.Write(" " + v); Console.WriteLine(); } } }