0

Im trying

    SearchResultCollection src = searcher.FindAll();
    string[,] newLine = new string[src.Count, 4];

    foreach (SearchResult res in src)          
    {
        newLine[rowID, ] = new string[ , ] {"value1", "value2", "value3", "value4"};  //Syntax error; value expected

but not luck -> Syntax error; value expected on the line above

3
  • 1
    What are you trying to accomplish? It's not very clear - it appears that you're trying to build a 2D array, with 4 values in the first dimension and a rowID in the second dimension (wouldn't it make more sense to do it the otherway around?). What your code would do (if it compiled) is reinitialize the array for each loop through the foreach. Can you clarify what it is you want to accomplish? Commented Aug 30, 2011 at 5:02
  • Tim, basically I have to fill a 2D array according to the number of records on my query but may be I should create the array using the count property from my record set, string[,] newLine = new string[src.Count, 4]; Commented Aug 30, 2011 at 5:12
  • I've added an answer. It's not the most elegant solution, but it should fill your array based on your comment. Commented Aug 30, 2011 at 5:21

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

Have a look at Array.Copy.

Comments

1

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] = "....";
            }
        }

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.