gpt4 book ai didi

c# - 如何在 C# 中用零初始化双维数组

转载 作者:可可西里 更新时间:2023-11-01 08:16:42 24 4
gpt4 key购买 nike

我是 C# 的新手。我有二维数组。我想用 0 进行初始化。

这是代码。我在 Array.fill()

处出错
int N = elements;
int M N * 2;
int[,] amn = new int[M,N];
for(int i = 0; i < M; i++)
Arrays.fill(amn[i], 0);

最佳答案

您无需执行任何操作。

来自 Arrays (C# Programming Guide)

The default values of numeric array elements are set to zero, andreference elements are set to null.

所以,当你写的时候;

int[,] amn = new int[M,N];

所有元素初始化为0

在调试器上可以看到;

enter image description here

关于c# - 如何在 C# 中用零初始化双维数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19157530/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com