简体   繁体   English

有人可以在C#中帮助我处理数组吗?

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

相关问题 有人可以在C#中帮我解决这个问题吗 - Can someone help me solve this in c# 我如何在 C# 中执行它有人可以帮助我 - how can i execute this in C# can someone help me 有人可以帮我重构C#linq业务逻辑以提高效率吗? - Can someone help me refactor this C# linq business logic for efficiency? 有人可以为我提供有关C#Datagridview双击行的帮助 - Someone can help me about c# datagridview double click row 有人可以帮我将这个用C#编写的正则表达式转换为javascript吗? - Can someone help me to convert this regex expression written in C# to javascript? 在此特定示例(IP地址表达式)中,有人可以帮助我比较使用F#和C#吗? - Can someone help me compare using F# over C# in this specific example (IP Address expressions)? 有人可以帮我修改此代码,使其在 C# ASP.NET 中工作吗? - Can someone help me to modify this code so it works in C# ASP.NET? 有人可以帮我保存脚本或打开 Monaco api 吗? C# - Can someone help me to save script or open into/from Monaco api? C# 有人可以使用C#统一代码为我的测验游戏提供帮助吗 - Can someone help me in my Quiz Game using C# unity code 有人可以帮我确定为什么 C# 工具提示不应该显示吗? - Can someone help me identify why C# tooltips show when they shouldn't?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM