如何在C#中以零初始化双维数组 [英] How to initialize double dimensional array with zero in c#
本文介绍了如何在C#中以零初始化双维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是新的C#。我有二维阵列。我想与 0
初始化。
下面是code。
我在 Array.fill()
INT N =元素;
INT M = N * 2;
INT [,] AMN = INT新[M,N];
的for(int i = 0; I<米;我++)
Arrays.fill(AMN [I],0);
解决方案
您不需要做任何事情。
数字数组元素的默认值被设置为零,并
参考元素设置为NULL。
块引用>所以,当你写;
INT [,] AMN = INT新[M,N];
initalized到
0
所有元素。您可以看到调试;
I'm new to c#. I have two dimensional array. I want to initialize with
0
.Here is code. I have an error at
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);
解决方案You don't need to do anything.
From
Arrays (C# Programming Guide)
The default values of numeric array elements are set to zero, and reference elements are set to null.
So, when you write;
int[,] amn = new int[M,N];
all elements initalized to
0
.You can see on debugger;
这篇关于如何在C#中以零初始化双维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文