// 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; using System.Collections.Generic; namespace E { public class Product { private string name; private decimal price; public Product(string name) : this(name, 0m) { } public Product(string name, decimal price) { this.name = name; this.price = price; } public string Name { get { return name; } } public decimal Price { get { return price; } set { price = value; } } public override string ToString() { return "[" + name + ":" + price + "]"; } } public class Program { public static void Main(string[] args) { List lst = new List(); lst.Add(new Product("A", 1.00m)); lst.Add(new Product("BB", 2.00m)); lst.Add(new Product("CCC", 3.00m)); foreach(Product p in lst) { Console.WriteLine(p); } lst.ForEach((Product p) => p.Price *= 1.1m); foreach(Product p in lst) { Console.WriteLine(p); } } } }