[英]Can someone help me with arrays in c#?
Well basicly had some trouble with placing my teams like so: http://pastebin.com/ahgP04bU 基本上,在像这样放置我的团队时遇到了一些麻烦: http : //pastebin.com/ahgP04bU
So I asked someone for advice and he just gave me a tip. 所以我向某人求教,他只是给了我小费。 And he said it has something to do with arrays.
他说,这与数组有关。 Follwing that he sended me a this code...
认为他给我发了这个代码...
string[,] clubs = new string[20,30];
clubs[0,1] = “spain”;
clubs[0,2] = etc;
What I don't understand is those comma's. 我不明白的是那些逗号。 And what does that [20,30] indicate?
[20,30]表示什么? And how does this help me place my teams in the way I want it (look on the pastebin link).
以及这如何帮助我按自己的方式放置团队(请查看pastebin链接)。
Or if you think you have a better link for me to help me out with arrays in datasets I would appreciate it. 或者,如果您认为有更好的链接可以帮助我解决数据集中的数组,我将不胜感激。
best regards, 最好的祝福,
That is a two-dimensional array, you can imagine them like a table. 那是一个二维数组,您可以想象它们像一张桌子。 The first index is the row, the second is the column.
第一个索引是行,第二个索引是列。
0 1 2 3 4 5 6
---|----------------
0 | x
1 |
2 |
3 |
The element denoted by the x
would be [0,1]
. x
表示的元素为[0,1]
。
new string[20,30]
creates a new multi-dimensional array. new string[20,30]
创建一个新的多维数组。 Where 20 indicates the array-width and 30 the array-height. 其中20表示数组宽度,30表示数组高度。 Think of it like this:
这样想:
If you create an array with the width 5 and height 5, you are basically creating 5*5 "slots" for strings that you can set. 如果创建宽度为5且高度为5的数组,则基本上是为可设置的字符串创建5 * 5“槽”。 You can access a specific slot by its coordinates.
您可以通过其坐标访问特定的插槽。
This code: 这段代码:
string[,] clubs = new string[5,5];
clubs[0, 1] = "a";
clubs[1, 4] = "b";
clubs[3, 2] = "c";
Creates an array like this: 创建一个像这样的数组:
0 1 2 3 4
0 "" "" "" "" ""
1 "a" "" "" "" ""
2 "" "" "" "c" ""
3 "" "" "" "" ""
4 "" "b" "" "" ""
It a 2 way multi diamensional array. 它是一种2向多维阵列。
refer to msdn for more information . 有关更多信息,请参考msdn 。
First number means number of rows, second columns 第一个数字表示行数,第二个列
string [,] myArray = new string[2,3] 字符串[,] myArray =新字符串[2,3]
would be 2 rows & 3 columns 将是2行和3列
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.