// 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 Type { Unknown, Sedan, Hatchback, Stationcar, SUV } public enum Color { Unknown, Red, Green, Blue, Yellow, White, Black } public class Car { public Type Type { get; set; } public Color Color { get; set; } public Car(params Action[] customizations) { foreach(Action onecustomization in customizations) { onecustomization(this); } } public override string ToString() { return String.Format("Car : {0} {1}", Type, Color); } public static Car MakeCustomCarWithColor(Color color) { return new Car(c => c.Color = color); } public static Car MakeCustomCarWithType(Type type) { return new Car(c => c.Type = type); } public static Car MakeCustomCarWithTypeAndColor(Type type, Color color) { return new Car(c => c.Type = type, c => c.Color = color); } } public class Program { public static void Main(string[] args) { Console.WriteLine(Car.MakeCustomCarWithColor(Color.Red)); Console.WriteLine(Car.MakeCustomCarWithType(Type.Sedan)); Console.WriteLine(Car.MakeCustomCarWithTypeAndColor(Type.Sedan, Color.Red)); } } }