这看起来非常简单,但我似乎无法在任何地方找到适用的文档。在 C# 中,如何创建“double[,]”?具体来说,我要表示的数据是这样的:
[0,0] = 0
[0,1] = 1
[1,0] = 1
[1,1] = 2
我已经尝试过 [[0,1],[1,2]] 和 {{}{}} 和 {[][]} 的等价物以及其他各种东西,但似乎无法弄清楚语法。似乎一个简单的 [0,1] 单独是一个 'double[,]' 但我想找到一种方法来表示上述数据(不仅仅是 2 个数字)。
我错过了什么?如果有人能给我指出一些简单的文档,那就太好了。
最佳答案
参见 Array initializers :
For a multi-dimensional array, the array initializer must have as many levels of nesting as there are dimensions in the array. The outermost nesting level corresponds to the leftmost dimension and the innermost nesting level corresponds to the rightmost dimension. The length of each dimension of the array is determined by the number of elements at the corresponding nesting level in the array initializer. For each nested array initializer, the number of elements must be the same as the other array initializers at the same level.
在我们的例子中:
double[,] a = { { 0, 1 }, { 1, 2 } };
关于c# - 在 C# 中创建 double[,] 的语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38385611/