c# - 在 C# 中创建 double[,] 的语法

标签 c# syntax double

这看起来非常简单,但我似乎无法在任何地方找到适用的文档。在 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/

相关文章:

java - 从标准输入中查找三个 double 中的最大值

C# - 从 app.config 有条件地将属性应用于方法

c# - 持久资源管理器 (IEnlistmentNotification) 恢复

c++ - 在即将到来的 c++0x 标准下,我们可以通过这种语法将数组作为参数传递给函数吗?

bash - 为什么 source 命令不适用于 bash 3.2 中的进程替换?

php - 语法错误,意外 '}'

c# - 如何将点移动给定距离 d(并获得新坐标)

c# - 如何在 C# 中的一个连接字符串中连接到两个数据库?

Android - 避免字符串中的指数转换为双倍转换

java - 为什么 Java 除以 0.0 时不抛出异常?