First, answering the question about two "different get set". Your problem is not "get/set", but "this". Yes, you can make more that one "this", and the idea is pretty cunning. I'll explain how to do this, but it may not help you. How do you think the user code can tell one "this" from another "this"? Only be different index (or by different number of indices). Is you are interested to have two arrays in the same class (by some weird reason; I don't think you really need it), the index types would be different.
You know what? I'll assume you have two underlying arrays: one of rank 1, another of rank 2. This will resolve the issue and demonstrate the technique.
Now, I'll explain the idea. Read my leaps:
declare two different indexed properties in two different interfaces and make your class implementing both interfaces. In fact, it's enough to have one interface.
internal interface ITwoDimensionalArray {
int this[int x, int t] { get; set; }
}
internal class DoubleArray : ITwoDimensionalArray {
internal DoubleArray(int arraySize, int array2SizeX, int array2sizeY) {
array = new int[arraySize];
array2 = new int[array2SizeX, array2sizeY];
}
int[] array;
int[,] array2;
public int this[int x, int y] {
get { return array2[x, y]; }
set { array2[x, y] = value; }
}
public int this[int index] {
get { return array[index]; }
set { array[index] = value; }
}
}
Problem solved!
Now (sight…), about your "soft failure". Bad idea! I'll now tell you what you should do, and you please don't get angry but think on what I suggests:
What the exceptions are for? Do not abuse them.
Do the following: never check up any array index ranges or something like that. You don't need you "defensive" style of programming, you need "offensive" style. Let the user to make a mistake in range and
let exceptions go! Of course, provide read-only access to the current array dimensions, but no more. What you do will only lead to a change of silent mistake. Who needs it. Exception would propagate somewhere on top of stack and will give the user a chance to fix the problem, if this is a bug. If there are no bug but there is an exception handled on top of UI cycle, the user will see some operation has failed. This is much better then the silent "soft" error.
So many inexperience developers abuse of misuse exceptions. Please read some of my past directions, it might help:
How do i make a loop that will stop when a scrollbar reaches the bottom[
^],
When i run an application an exception is caught how to handle this?[
^],
throw . .then ... rethrowing[
^].
—SA