Passing one Dimension of a Two Dimensional Array in C#

后端 未结 6 939
耶瑟儿~
耶瑟儿~ 2021-01-21 07:31

I have moved from C to C#. I have a function which accepts an array. I want to pass one dimension of a Two Dimensional array to this function.

C Code would be:-

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-21 08:01

    Late to the conversation, but here is a jagged array example to do this:

    string[][] rows = GetStringArray(values);
    string[] row = rows[0];
    

    You would set up your jagged array something like:

    // rowCount from runtime data
    stringArray = new string[rowCount][];
    
    for (int index = 0; index < rowCount; index++)
    {
        // columnCount from runtime data
        stringArray[index] = new string[columnCount];
    
        for (int index2 = 0; index2 < columnCount; index2++)
        {
            // value from runtime data
            stringArray[index][index2] = value;
        }
    }
    

提交回复
热议问题