using System; public class Test { public static void Main() { //init and print Console.WriteLine("Init"); SpecialArray test = new SpecialArray(0, 10); test.Print(); //set all and print Console.WriteLine("Set All to 12"); test.SetAll(12); test.Print(); //set some values and print Console.WriteLine("Set some values"); test.Set(4, 3); test.Set(6, 2); test.Set(0, 0); test.Print(); //set all again and print Console.WriteLine("Set all to 14"); test.SetAll(14); test.Print(); //set some values again and print Console.WriteLine("Set some values"); test.Set(4, 4); test.Set(6, 5); test.Set(0, 6); test.Print(); //set all again and print Console.WriteLine("Set all to 16"); test.SetAll(16); test.Print(); //printing tests the Get method works Console.ReadLine(); } } public class SpecialValue { public bool mode = true; public bool haslocal = false; public T local; } public class SpecialArray { SpecialValue[] array; bool mode; int size; T globalTrue; T globalFalse; public SpecialArray(T globalValue, int size) { this.size = size; mode = true; globalTrue = globalValue; array = new SpecialValue[size]; for (int i = 0; i < size; i++) array[i] = new SpecialValue(); } public T Get(int i) { SpecialValue val = array[i]; if (val.mode == mode) { if (val.haslocal) return val.local; else return val.mode ? globalTrue : globalFalse; } else { val.mode = mode; val.haslocal = false; return val.mode ? globalTrue : globalFalse; } } public void Set(int i, T value) { SpecialValue val = array[i]; val.haslocal = true; val.local = value; } public void SetAll(T value) { mode = !mode; if (mode) globalTrue = value; else globalFalse = value; } public void Print() { for (int i = 0; i < size; i++) Console.Write(Get(i).ToString() + ", "); //meh good enough Console.WriteLine(); } }