public static void GetQuantityTwo() { // get a random quantity DemoModule3.Quantity q = DemoModule3.getRandomQuantity(); // use if ... else chain to display value if (q.IsDiscrete) { Console.WriteLine("Discrete value: {0}", (q as DemoModule3.Quantity.Discrete).Item); } else if (q.IsContinuous) { Console.WriteLine("Continuous value: {0}", (q as DemoModule3.Quantity.Continuous).Item); } }
public static void GetQuantityOne() { // get a random quantity DemoModule3.Quantity q = DemoModule3.getRandomQuantity(); // use the .Tags property to switch over the quatity switch (q.Tag) { case DemoModule3.Quantity.Tags.Discrete: Console.WriteLine("Discrete value: {0}", (q as DemoModule3.Quantity.Discrete).Item); break; case DemoModule3.Quantity.Tags.Continuous: Console.WriteLine("Continuous value: {0}", (q as DemoModule3.Quantity.Continuous).Item); break; } }
public static void GetQuantityZero() { // initialize both a Discrete and Continuous quantity DemoModule3.Quantity d = DemoModule3.Quantity.NewDiscrete(12); DemoModule3.Quantity c = DemoModule3.Quantity.NewContinuous(12.0); }