Tuesday, February 5, 2008

c# Performance snippet - looping through a multidimensional array

Within the CLR there is an optimization for loops that has a termination checkpoint against the length property of the collection/array. However this is not implemented for multidimensional arrays.
In order to achieve better performance when the need arises to use multidimensional arrays its better to use Jagged arrays (Jagged array or arrays)

Example of a jagged array:

int[][] arrJagged = new int[][]{new int[]{1,2,3,4,5},new int[]{2,3,4,5,6}};

No comments: