Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multidimensional vs Jagged array

I have used a MultiDimesional Array as follows

  string[,] Columns = { { "clientA", "clientB" }}

    if (Columns.Length != 0)
            {
                for (int i = 0; i < Columns.Length / 2; i++)
                {
                    bulkCopy.ColumnMappings.Add(Columns[i, 0], Columns[i, 1]);
                }
            }

After code analysis I got warning message as

Severity    Code    Description Project File    Line    Suppression State
Warning CA1814  'Order.GetLastOrderID()' uses a multidimensional array of  
'string[,]'. Replace it with a jagged array if possible.    

I have researched jagged arrays on internet but How do I replace my array with jagged array.


1 Answers

A jagged array is an array of arrays, so you change your definition to:

string[][] Columns = { new string[] { "clientA", "clientB" }};

Change array access from...

var value = Columns[0,0];

...to...

var value = Columns[0][0];

You also have the option to suppress the warning (right-click on it and select the option you need). According to MSDN, this is a warning that is safe to suppress in certain cases. Check if yours is such a case before you change the code.

like image 197
Sefe Avatar answered Jun 25 '26 02:06

Sefe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!