// Collection of code snippets by Arne Vajhøj // (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) using System; namespace E { public enum MyIndex { ONE, TWO, THREE } public class MyIntArray { private int[] data = new int[Enum.GetValues(typeof(MyIndex)).Length]; private int RealIndex(MyIndex ix) { return (int)ix - (int)Enum.GetValues(typeof(MyIndex)).GetValue(0); } public int this[MyIndex ix] { get { return data[RealIndex(ix)]; } set { data[RealIndex(ix)] = value; } } } public class Program { public static void Main(string[] args) { MyIntArray mia = new MyIntArray() {[MyIndex.ONE] = 123,[MyIndex.TWO] = 456,[MyIndex.THREE] = 789 }; Console.WriteLine(mia[MyIndex.TWO]); } } }