多维数组对一维 [英] Multi-dimensional array vs. One-dimensional

查看:235
本文介绍了多维数组对一维的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这基本上是这个问题的重述:<一href=\"http://stackoverflow.com/questions/2512082/java-multi-dimensional-array-vs-one-dimensional\">Java:多维数组与一维的。但对于C#。

This is basically a restatement of this question: Java: Multi-dimensional array vs. One-dimensional. but for C#.

我有意义的存储为网格元素的集合量。
我应该使用一个数组[X * Y]或数组[X] [Y]?

I have a set amount of elements that make sense to store as a grid. Should I use a array[x*y] or a array[x][y]?

编辑:哦,所以有一维数组[X * Y],多维数组[X,Y]和交错数组[X] [Y],我可能想锯齿状

Oh, so there are one dimensional array[x*y], multidimensional array[x,y] and jagged array[x][y], and I probably want jagged?

推荐答案

有在C#中很多优点,使用的交错数组数组[] [] )。他们实际上往往会跑赢多维数组。

There are many advantages in C# to using jagged arrays (array[][]). They actually will often outperform multidimensional arrays.

话虽这么说,我会亲自使用多维或锯齿状排列,而不是一个单一的维数组,因为这更加紧密地问题空间相匹配。使用一维数组增加复杂的实现,并不提供真正的实惠,特别是相对于一个二维数组的时候,作为在内部,它仍然是一个单独的内存块。

That being said, I would personally use a multidimensional or jagged array instead of a single dimensional array, as this matches the problem space more closely. Using a one dimensional array is adding complexity to your implementation that does not provide real benefits, especially when compared to a 2D array, as internally, it's still a single block of memory.

这篇关于多维数组对一维的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆