// 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.IO; namespace E { public delegate void LineProcessor(string line); public delegate void EndProcessor(); public class EventReader { public event LineProcessor GotLine; public event EndProcessor GotEnd; private TextReader tr; public EventReader(TextReader tr) { this.tr = tr; } public void Run() { String line; while((line = tr.ReadLine()) != null) { GotLine(line); } GotEnd(); } } public class Program { public static void DumpLine1(string line) { Console.WriteLine("1: {0}", line); } public static void DumpLine2(string line) { Console.WriteLine("2: {0}", line); } public static void End() { Console.WriteLine("STOP"); } public static void Main(string[] args) { EventReader er = new EventReader(Console.In); er.GotLine += DumpLine1; er.GotLine += DumpLine2; er.GotEnd += End; er.Run(); } } }