任何人都可以解释下面的代码是怎么回事? [英] can anyone explain what going on with the follwing code?
本文介绍了任何人都可以解释下面的代码是怎么回事?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下代码是做什么的
what is the following code doing
int[] lstNumbers = p.RandomNumbers();
int[,] array = new int[3, 3];
此方法
in this method
int k = 1;
int[] lstNumbers = p.RandomNumbers();
int[,] array = new int[3, 3];
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
array[i, j] = lstNumbers[k - 1];
k++;
}
}
实际上我只是想知道int [,] array = new int [3,3]
它会创建一个3行和3列矩阵,但为什么我们写int [,] ??
actually i just want to know int[,] array =new int [3,3]
it will create a 3 row and 3 columns matrix but why we write int[,]??
推荐答案
也许你应该看看MSDN。
http://msdn.microsoft.com/en-us/library/2yd9wwz4.aspx [ ^ ]
int i [,]
告诉编译器它是一个具有两个维度的多维数组。
然后在下一部分new int [3,3 ]
你告诉编译器每个维度的长度。
这样简单。
Maybe you should take a look at MSDN.
http://msdn.microsoft.com/en-us/library/2yd9wwz4.aspx[^]
int i[,]
tells the compiler that it is a multi dimensional array with two dimensions.
Then in the next partnew int [3,3]
you tell the compiler the length of each dimension.
Simple as that.
浏览此链接: http://msdn.microsoft.com/en-us/library/aa288453(v = vs.71).aspx [ ^ ]
它将回答你的所有问题。
:)
Hi,
Go through This link : http://msdn.microsoft.com/en-us/library/aa288453(v=vs.71).aspx[^]
it will answer all of your questions.
:)
这篇关于任何人都可以解释下面的代码是怎么回事?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文