// 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 class Entry { public DateTime TimeStamp { get; set; } public U Value { get; set; } } private IList> data = new List>(); public void Add(T o) { data.Add(new Entry{TimeStamp = DateTime.Now, Value = o}); } public IList GetList() { DateTime cut = DateTime.Now.AddSeconds(-3); return data.Where(e => e.TimeStamp < cut).Select(e => e.Value).ToList(); } } public class Program { public static void Main(string[] args) { DelayedContainer lst = new DelayedContainer(); for(int i = 1; i <= 10; i++) { lst.Add(i); Console.WriteLine("Adding " + i); 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(); } } }