开发者

Can someone help me with arrays in c#?

Well basicly had some trouble with placing my teams like so: 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? And how does this he开发者_如何学Clp me place my teams in the way I want it (look on the pastebin link).

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].


new string[20,30] creates a new multi-dimensional array. Where 20 indicates the array-width and 30 the array-height. 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. 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.

refer to msdn for more information.

First number means number of rows, second columns

string [,] myArray = new string[2,3]

would be 2 rows & 3 columns

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜