nene, ein Array ist in .Net wird immer mit einem int indexiert.
Wenn du _wirklich_ über Point als Index zugriefen willst, könntest du dir einen Wrapper bauen, der zuweisungskompatibel ist (implizite Umwandlung).
Hier mal ein abstrakter Bleistift:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59:
| struct ArrayWrapper<T> { T[,] array;
public T this[Point index] { get { return array[index.X, index.Y]; } set { array[index.X, index.Y] = value; } }
public T this[int index1, int index2] { get { return array[index1, index2]; } set { array[index1, index2] = value; } }
ArrayWrapper(T[,] array) { this.array = array; }
public static implicit operator ArrayWrapper<T>(T[,] value) { return new ArrayWrapper<T>(value); }
public static implicit operator T[,](ArrayWrapper<T> value) { return value.array; } }
class Program { static void Main(string[] args) {
ArrayWrapper<int> wrapper = new int[3, 1];
Point point00 = new Point(0, 0); Point point01 = new Point(0, 1); Point point10 = new Point(1, 0); Point point11 = new Point(1, 1);
wrapper[point00] = 1; wrapper[point01] = 2; wrapper[point10] = 3; wrapper[point11] = 4;
wrapper[3, 0] = 5; wrapper[3, 1] = 6;
int[,] values = wrapper;
foreach (int i in values) Console.WriteLine(i); } } |
Für eine wirklich gute Idee halte ich es aber nicht...
@christian
Dictionary<Point, int> würde sich zwar nicht genauso verhalten, aber genau genug. Boah hatte wohl die sprichwörtichen Tomaten auf den Augen