3

I'm trying to convert vb6 code to c# code. My vb6 source code contains arrays of the most varied types and after conversion by Vs2005 tools these arrays have become 0-based array, but I need to reconvert to non-0-based array.So for example I try to use Array.CreateInstance with explicit cast to T[] for a generic use:

public void ResizeArrayBaseN<T>(ref T[] original, int firstLower, int firstCount)
{
    try
    {
        int[] myBoundsArray = new int[1] {firstLower };
        int[] myLengthsArray = new int[1] {firstCount - firstLower + 1 };
        original = (T[])Array.CreateInstance(typeof(T), myLengthsArray, myBoundsArray);
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

But I'm catching cast from T[*] to T[] error. Can someone help me,please ? Thanks in advance

Patrick Artner
  • 50,409
  • 9
  • 43
  • 69

1 Answers1

5

A T[] is a vector array - a zero-based one-dimensional array. You cannot use T[] to represent an array with a non-zero base, because: it isn't a vector. This is what the * in T[*] means. I suspect it can only be referenced as an Array - making it quite inconvenient to use.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900