Is there a way to convert a boxed two-dimensional array to a two-dimensional string array in one step using C#/.NET Framework 4.0?
using ( MSExcel.Application app = MSExcel.Application.CreateApplication() ) {
MSExcel.Workbook book1 = app.Workbooks.Open( this.txtOpen_FilePath.Text );
MSExcel.Worksheet sheet1 = (MSExcel.Worksheet)book1.Worksheets[1];
MSExcel.Range range = sheet1.GetRange( "A1", "F13" );
object value = range.Value; //the value is boxed two-dimensional array
}
I'm hopeful that some form of Array.ConvertAll might be made to work but so far the answer has eluded me.
You can write your own
ConvertAll
for two-dimensional arrays:Edit: The clarification about object[,] instead of object[][] obviously makes this approach obsolete. An interesting problem; multidimensional arrays are quite limited.
No, I do not think you can make the conversion in one step, but I might be wrong. But you can of course create a new array and copy from the old one to the new one:
Edit:
Here is a two-dimensional overload of
Array.ConvertAll
which is not that much more complicated than the code above: