// 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; public class MyData { private string s; public MyData() : this("") { } public MyData(string s) { this.s = s; } public string S { get { return s; } set { s = value; } } } public class MyCollection : CollectionBase { private bool ro = false; public MyData this[int index] { get { return (MyData)List[index]; } } public int Add(MyData o) { if(ro) { throw new Exception("List is readonly"); } return List.Add(o); } public bool ReadOnly { get { return ro; } set { ro = value; } } } class TestClass { public static void Main(string[] args) { MyCollection mycol = new MyCollection(); mycol.Add(new MyData("A")); mycol.Add(new MyData("BB")); mycol.ReadOnly = true; mycol.Add(new MyData("CCC")); for(int i = 0; i < mycol.Count; i++) { Console.WriteLine(mycol[i].S); } } }