Pat

Pat

  • NA
  • 3
  • 0

Dynamic array!

Jan 11 2007 10:58 AM

I am converting vb6 code to C# and I have a question regarding  array argument. In vb6 the array argument below sometimes take the form of 1Dimension or MultiD where it is Redim depending on how it comes. C# does not allow this.....my question is, how do I handle it?


public double[] ConvertMatrixToBase0(double[] MyMat)
{
 long i, j;
 double[] ConvMat;

 if(MultiDimensional(MyMat) == false) //1-dimensional array
 {
  ConvMat = new double[MyMat.GetLength(1) - 1]; //ReDim ConvMat(UBound(MyMat, 1) - 1)
  for(i=1; i<=MyMat.GetLength(1); i++) //For i = 1 To UBound(MyMat, 1)
  ConvMat[i - 1] = MyMat[i];

 }
 else     //multi-dimensional array
 {
  ConvMat = new double[MyMat.GetLength(1)-1, MyMat.GetLength(2)-1]; //ReDim ConvMat(UBound(MyMat, 1) - 1, UBound(MyMat, 2) - 1)
  for(i=1; i<=MyMat.GetLength(1); i++) //For i = 1 To UBound(MyMat, 1)
  {
   for(j=1; j<=MyMat.GetLength(2); j++) //For j = 1 To UBound(MyMat, 2)
   ConvMat[i-1,j-1] = MyMat[i,j];
  } 
  }

 return ConvMat;
}