// 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; namespace Blocks { public static class Luck { private static Random rng = new Random(); public static bool InLuck() { return rng.NextDouble() > 0.2; } } public class X { private string id; private X(string id) { this.id = id; Console.WriteLine("X {0} created", id); } public static X Create(string id) { if(Luck.InLuck()) { return new X(id); } else { return null; } } public void Close() { Console.WriteLine("X {0} closed", id); } } public class Program { public static void Main(string[] args) { X o1 = X.Create("A"); if(o1 != null) { X o2 = X.Create("B"); if(o2 != null) { // 20 lines Console.WriteLine("Part 1"); if(Luck.InLuck()) { // 20 lines Console.WriteLine("Part 2"); } else { Console.WriteLine("Error during execution"); } o2.Close(); } else { Console.WriteLine("Error creating B"); } o1.Close(); } else { Console.WriteLine("Error creating A"); } } } }