I have converted about 4000-5000 lines of code from VBA to C#. The only issue I have is the following:
In VBA you can create an array of a type and also set the start index. For example:
//This creates an Array with an index 5 to index 100.
doubleArray(5 To 100) As Double
It is not possible in C# to create an array that starts at an index other than 0. (See the link below.) In my opinion that will leave the following two possibilities:
1. Create a doubleArray from 0 to 100
I could create an doubleArray as follows:
Double[] doubleArray = new Double[100];
This has as an advantage that I can set the index by using the index number described as in the VBA code. This means the following; The VBA code assumes that the array exists from [5] to [100] and I am also able to set the number 5 to 100 in C#.
In my opinion however this is quite messy, because you will always create arrays with unused memory (in this case index [0] to index [4]). Because of this I was thinking of the second option.
2. Create a doubleArray from 0 to ((topindex - bottomindex) + 1)
I Could create a doubleArray as follows:
Double[] doubleArray = new Double[((topindex - bottomindex) + 1)];
In my opinion this should be the 'cleanest' way to overcome the problem, without unnecessary memory usage. In VBA the array uses [5] to [100], that makes the length 96. The same is the case for this option ( ((100 - 5) + 1) = 96 ).
However the big downside is that this would also require to overlook all the code that has already been written. If any function calls doubleArray[97], it should be doubleArray[((97 - 5) + 1)].
My question is thus, how to handle with this situation?
If anyone else sees another option/possibility, suggestions are more than welcome.
For some more background information. A follow-up from my earlier question: Vba Type-Statement conversion to C#