How load multiple values into a multidimensional array in a single line
Im trying
SearchResultCollection src = searcher.FindAll();
string[,] newLine = new string[src.Count, 4];
foreach (SearchResult res in s开发者_C百科rc)
{
newLine[rowID, ] = new string[ , ] {"value1", "value2", "value3", "value4"}; //Syntax error; value expected
but not luck -> Syntax error; value expected on the line above
Based on the OP's clarification, something like this might work.
string[ , ] newLine = new string[src.Count, 4];
for (int i = 0; i < src.Count; i++)
{
newLine[i, 0] = value1;
newLine[i, 1] = value2;
newLine[i, 2] = value3;
newLine[i, 3] = value4;
}
Maybe not the prettiest solution, but it'll do the job.
Have a look at Array.Copy
.
for a exsample...
string[,] newLine = new string[src.Count, 4];
for (int i = 0; i < newLine.GetUpperBound(0); i++)
{
for (int j = 0; j < newLine.GetUpperBound(1); j++)
{
newLine[i, j] = "....";
}
}
精彩评论