What's better in regards to performance? type[,] or type[][]?

前端 未结 4 809
野的像风
野的像风 2021-01-18 23:27

Is it more performant to have a bidimensional array (type[,]) or an array of arrays (type[][]) in C#?

Particularly for initial allocation a

4条回答
  •  庸人自扰
    2021-01-19 00:31

    It really depends. The MSDN Magazine article, Harness the Features of C# to Power Your Scientific Computing Projects, says this:

    Although rectangular arrays are generally superior to jagged arrays in terms of structure and performance, there might be some cases where jagged arrays provide an optimal solution. If your application does not require arrays to be sorted, rearranged, partitioned, sparse, or large, then you might find jagged arrays to perform quite well.

提交回复
热议问题