Total .NET Analyzer Rule Documentation  

MultiDimensionalArray Rule

Avoid using multi-dimensional arrays.

Remarks

When possible, you should avoid using multi-dimensional arrays, use jagged arrays instead. The .NET JIT Compiler optimizes jagged arrays more efficiently than rectangular arrays.

Resolution

Since a multi-dimensional array can have a negative performance impact, you should replace it with a jagged array (an array-of-arrays) if possible.

In Visual Basic, you could replace a multi-dimensional array such as:

Dim myMultiDimArray(4, 9) As String

With a jagged array such as:

Dim myJaggedArray(4)() As String

In C#, a multi-dimensional array such as:

string[,] myMultiDimArray = new string[4,9];

Could be replaced by a jagged array such as:

string[][] myJaggedArray = new string[4][];

See Also

Performance Tips and Tricks