All rules
CA1814Performance Enabled by default: No

Prefer jagged arrays over multidimensional

Prefer jagged arrays over multidimensional

Microsoft docs

Description

In a multidimensional array, each element in each dimension has the same, fixed size as the other elements in that dimension. In a jagged array, which is an array of arrays, each inner array can be of a different size. By only using the space that's needed for a given array, no space is wasted. This rule, CA1814, recommends switching to a jagged array to conserve memory.

Cause

A member is declared as a multidimensional array, which can result in wasted space for some data sets.

How to fix violations

To fix a violation of this rule, change the multidimensional array to a jagged array.

Example

#pragma warning disable CA1814
// The code that's violating the rule is on this line.
#pragma warning restore CA1814

When to suppress

It's okay to suppress a warning from this rule if the multidimensional array does not waste space.

Group results
0 yes 0 no
ConsensusNone (disabled)
Severity preference (yes voters)
Suggestion0
Warning0
Error0