// Collection of code snippets by Arne Vajhøj // (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) using System; public class XS7 { public enum Sign { POSITIVE, NEGATIVE } public static Sign MultiplicationSign(Sign s1, Sign s2) { switch(s1) { case Sign.POSITIVE: switch(s2) { case Sign.POSITIVE: return Sign.POSITIVE; case Sign.NEGATIVE: return Sign.NEGATIVE; } break; case Sign.NEGATIVE: switch(s2) { case Sign.POSITIVE: return Sign.NEGATIVE; case Sign.NEGATIVE: return Sign.POSITIVE; } break; } throw new Exception("We should never end here"); } public static void Main(string[] args) { foreach(Sign s1 in Enum.GetValues(typeof(Sign))) { foreach(Sign s2 in Enum.GetValues(typeof(Sign))) { Console.WriteLine("{0} * {1} = {2}", s1, s2, MultiplicationSign(s1, s2)); } } } }