// 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 E { public enum StatusB { OK, ERROR } public enum StatusA { OK, ERROR } public class B { public B() { Console.WriteLine("B ctor"); } public StatusB DoSomething() { return StatusB.ERROR; } public void Close() { Console.WriteLine("B Close"); } } public class A { public A() { Console.WriteLine("A ctor"); } public StatusA DoSomething() { return StatusA.OK; } public StatusA DoSomethingElse(B ob) { StatusB stat = ob.DoSomething(); if(stat == StatusB.OK) { return StatusA.OK; } else { return StatusA.ERROR; } } public void Close() { Console.WriteLine("A Close"); } } public class Program { public static void Main(string[] args) { A oa = new A(); StatusA stat1 = oa.DoSomething(); if(stat1 != StatusA.OK) { Console.WriteLine("We have a problem"); goto close_a; } B ob = new B(); StatusA stat2 = oa.DoSomethingElse(ob); if(stat2 != StatusA.OK) { Console.WriteLine("We have a another problem"); goto close_b; } Console.WriteLine("Everything OK"); close_b: ob.Close(); close_a: oa.Close(); } } }