// 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; public class MyData { private string s; public MyData() : this("") { } public MyData(string s) { this.s = s; } public override string ToString() { return s; } public string S { get { return s; } set { s = value; } } } public class MyCollection : CollectionBase { public MyData this[int index] { get { return (MyData)List[index]; } } public int Add(MyData value) { return List.Add(value); } } class TypSafCol11 { public static void Main(string[] args) { MyCollection mycol = new MyCollection(); mycol.Add(new MyData("A")); mycol.Add(new MyData("BB")); mycol.Add(new MyData("CCC")); for(int i = 0; i < mycol.Count; i++) { Console.WriteLine(mycol[i]); } } }