two-dimensional string array help...

T

trint

I have 14 strings in each row that I need in a two-dimensional string
array and I know how many rows I've got.
I have two questions please:
1. How can I assign 14 string values in 14 elements per row, and then
process each row at a time?

int iNR = 379524;//<--Rows
// |------Columns
// v
string[,] numOfRows = new string[iNR,14];

2. How can I pass the two-dimemsional string array to another function?

Thanks,
Trint
 
N

Nicholas Paldino [.NET/C# MVP]

Trint,

You seem to have the code already. To process row by row, column by
column, you would do something like this:

// The string that is being processed.
string val;

// Loop through the rows.
for (int row = 0; row < numOfRows.GetLength(0); ++row)
{
// Loop through the columns.
for int col = 0; col < numOfRows.GetLength(1); ++col)
{
// Get the value.
val = numOfRows[row, col];

// Process the value.
}
}

To pass the array to a function, you would do it like any other
variable. Your signature would have to take a multi-dimensional array
though, like this:

public void DoSomething(string[,] array)
{
}

Hope this helps.
 
J

Jon Skeet [C# MVP]

trint said:
I have 14 strings in each row that I need in a two-dimensional string
array and I know how many rows I've got.
I have two questions please:
1. How can I assign 14 string values in 14 elements per row, and then
process each row at a time?

int iNR = 379524;//<--Rows
// |------Columns
// v
string[,] numOfRows = new string[iNR,14];

That declaration works fine. You can't process a single row as easily
as you would be able to with a jagged array, however.
2. How can I pass the two-dimemsional string array to another function?

Just pass it as you would do to anything else - so long as the method
accepts a two dimentional string array (or something else compatible
with it, such as object, Array or IList) it should be fine.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top