// Collection of code snippets by Arne Vajhøj // (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) using System; using System.Collections.Generic; public class I20 { public static void Main(string[] args) { // objekt initialisering P o = new P(); o.A = 123; o.B = "ABC"; Console.WriteLine(o.A + " " + o.B); // collection initialisering List lsti = new List(); lsti.Add(1); lsti.Add(2); lsti.Add(3); foreach(int v in lsti) Console.WriteLine(v); // kombineret List

lstp = new List

(); P o1 = new P(); o1.A = 123; o1.B = "ABC"; lstp.Add(o1); P o2 = new P(); o2.A = 456; o2.B = "DEF"; lstp.Add(o2); foreach(P v in lstp) Console.WriteLine(v.A + " " + v.B); } }