Casting multi dimensional arrays
-
I have an object that I am getting from an Excel cell range. I can look at it in the debugger, its an array of arrays (of objects I think). I want to store this in a variable, but I dont know how to cast it!! I DO know the size of the array of arrays (both, i am completely aware of the dimensions of this object.) Can somebody please help?? So you can see, here is what I have currently but it throws a cast exception: cellR = workS.get_Range("A" + curRow, "F" + curRow); Object theLine = cellR.get_Value(System.Type.Missing); Object[][] theOtherLine = new object[1][]; theOtherLine = (Object[][])theLine; It does so at runtime. Cheers! Jim Did I post well? Rate it! Did I post badly? Rate that too!
-
I have an object that I am getting from an Excel cell range. I can look at it in the debugger, its an array of arrays (of objects I think). I want to store this in a variable, but I dont know how to cast it!! I DO know the size of the array of arrays (both, i am completely aware of the dimensions of this object.) Can somebody please help?? So you can see, here is what I have currently but it throws a cast exception: cellR = workS.get_Range("A" + curRow, "F" + curRow); Object theLine = cellR.get_Value(System.Type.Missing); Object[][] theOtherLine = new object[1][]; theOtherLine = (Object[][])theLine; It does so at runtime. Cheers! Jim Did I post well? Rate it! Did I post badly? Rate that too!
Object[][] is a jagged array. Perhaps you need Object[,] ?? Christian Graus - Microsoft MVP - C++
-
Object[][] is a jagged array. Perhaps you need Object[,] ?? Christian Graus - Microsoft MVP - C++
-
Wow, thank you! How is that handled differtly in memory? Why do both of those exist? Cheers, Jim Did I post well? Rate it! Did I post badly? Rate that too!
Jagged arrays is simply an array of arrays, while a multidimensional array is truly one array with multiple dimensions. Jagged arrays can have different dimensions for each row in the first dimension, for eg, whereas multidimensional arrays always have the same number of dimensions.
int [][] x = new int[2][];
x[0] = new int[5]; // First row has 5 columns
x[1] = new int[10];// Second row has 10
...
int [,]x = new int[2,10]; // both rows have 10 columns.Regards Senthil _____________________________ My Blog | My Articles | WinMacro