// 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 class Unit { public string Name { get; set; } public string UnitType { get; set; } public double Tax { get; set; } public Unit(string name, string unittype, double tax) { this.Name = name; this.UnitType = unittype; this.Tax = tax; } } public class Program { public static double TotalTax(Unit[] ua) { double sum = 0; foreach(Unit u in ua) { sum += u.Tax; } return sum; } public static int NumberOfFactoryInstalled(Unit[] ua) { int sum = 0; foreach(Unit u in ua) { switch(u.UnitType) { case "Bil": case "Eftersmonteret udstyr": // nothing break; case "Fabriksmonteret udstyr": sum++; break; default: throw new ArgumentException("Not a valid unit type"); } } return sum; } public static void Main(string[] args) { Unit[] ua = new Unit[4]; ua[0] = new Unit("Folkevogn", "Bil", 240.00); ua[1] = new Unit("Udstyr #1", "Fabriksmonteret udstyr", 10.00); ua[2] = new Unit("Udstyr #2", "Fabriksmonteret udstyr", 50.00); ua[3] = new Unit("Udstyr #3", "Eftersmonteret udstyr", 200.00); Console.WriteLine(TotalTax(ua)); Console.WriteLine(NumberOfFactoryInstalled(ua)); } } }