数组中概念:

1           数组(System.Array):把许多类似的对象组合起来(是一个数据结构)。

1.1数组的使用:

1)声明。<baseType>[直接标出的是数组的长度] <name>; 但是[]则可表示变长。

2)在使用前,必须初始化。有两种方法:aint [ ] myArray; myArr y = {2,3}; 赋值 bint[ ] myArray = new int[5];定义了数组的大小其中int[ ] myArray = new int [变量];

2           数组中的数组(交错数组):对于变长数组。

1)声明:int[][] <name> 多了个[]

2)初始化:e.g

Int[][] array ; array = new int[2][]; array[0] = new int[3]; array[1] = new int[4]; (其中int[4]表示有5个元素)

注意在使用foreach时,<baseType><baseType>[].

 

定位数组中各个元素:

1 Foreach循环:定位数组中的每个元素。区别于for语句。Foreach循环对数组内容只读。

Foreach (<baseType> <name> in <array>)

{

                  //use <name> for each element

}

 

2 For语句的使用。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-11
  • 2022-12-23
  • 2022-12-23
  • 2021-06-16
  • 2021-12-14
猜你喜欢
  • 2022-12-23
  • 2021-07-07
  • 2022-12-23
  • 2022-12-23
  • 2021-10-02
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案