.NET Framework 2.0 Performance Inspection Questions - Arrays

From Guidance Share

Jump to: navigation, search


Do You Use Strongly Typed Arrays?

Identify places in your code where you use object arrays (arrays containing the Object type). If you use object arrays to store other types, such as integers or floats, the values are boxed when you add them to the array. Use a strongly typed array instead, to avoid the boxing. For example, use the following to store integers.


  int[] arrIn = new int[10];

Use the preceding to store integers instead of the following.


  Object[] arrObj = new Object[10];


Do You Use Multidimensional Arrays?

If your code uses multidimensional arrays, see if you can replace the code with a jagged array (a single dimensional array of arrays) to benefit from MSIL performance optimizations.

Note Jagged arrays are not CLS compliant and may not be used across languages. For more information, see "Use Jagged Arrays Instead of Multidimensional Arrays" in .NET 2.0 Performance Guidelines - Arrays

Personal tools