Freelance Project Requests Software Development in C# WPF Asp.Net Core Vba Excel Word SQL-Server EF Linq, UWP Net

C #: Converting a 2D Object Array to 2D String Array



This code example in C # shows how to transform a two-dimensional object [,] array into a 2-dimensional string [,] array.

The array consists of rows and columns, which result from the Excel-Used-Range in Interop.Excel


This shows in C #:

On the left, the objects [,] array of rows and columns from Excel

On the right the string [,] array, which contains only strings and no null values.



2 dimensional array in C #, Windows Forms


Transformation Code C #

For the objects [,] array to string [,] array

Excel.Range usedRange = _worksheet.UsedRange;

log_with_Date("get UsedRange", dtStart);


//*fast Excel-Read: 

//< create 2D Array >

//*from excel with cell-content-object

object[,] arrObjectValues = usedRange.Value2;


int nRows = arrObjectValues.GetLength(0);

int nColumns = arrObjectValues.GetLength(1);

string[,] arrStringValues = new string[nRows, nColumns];

//</ create 2D Array >


//--< convert array object to string >--

for (int iRow = 0; iRow < nRows ; iRow++)


    for(int iCol=0;iCol<nColumns ; iCol++)


        //< Convert object to string >

        arrStringValues[iRow, iCol] = Convert.ToString(arrObjectValues[iRow+1, iCol+1]);

        //</ Convert object to string >



//--</ convert array object to string >--



C #: Converting a 2D Object Array to 2D String Array
Asp.Net C #: Optional parameters in method
Asp.Net C #: Bool zero to bool
C#: Add Item to Array or List
C#: Split String into single Words String-Array
C#: Convert TimeSpan in Units of time, Seconds, Minutes
C#: convert var to int.
C#: Convert Var to Int
C#: line break in the code line new line
C#: Short Code in one line: result from if - else- then


Contact for Jobs, Project Requests: