24661人加入学习
(72人评价)
C#编程-第一季-编程基础-宇宙最简单2021最新版

制作完成于2021年10月10日,使用Visual Studio 2019

价格 免费

赋值需要加上一个new

int[] intarray = new int[9]

ages.Length 获取数组shu'xing

 

[展开全文]

foreach遍历

foreach方法仅限用于遍历集合类型的数据,如数组

例:

int[10] ages = { 34, 12, 56, 67, 2, 3, 4, 12, 16, 6};

foreach(int temp in ages){

}

 

[展开全文]

int[] a = new int[]{12,12,5,42,3}

a.Length;

for(int B = 0;B<a.Length;B++){

console.write(a[B]);

 

}

[展开全文]

数组的申明和 赋值必须放在同一行。

 

与java相同。

 

foreach 的语法:

foreach(数据类型  局部变量   in   集合) {

}

 

Java中 foreach的语法:

for(数据类型   局部变量  :  集合) {

}

[展开全文]

foreach:遍历数组命令 只能正序遍历

foreach(int temp in a)

{

Console.Write(a[i] + " ");

}

老办法:

for(int i=1;i<a.Length;i++) //获取数组个数

{

  Console.Write(a[i] + " ");

}

 

[展开全文]

foreach  只能正序

for( int temp in ages){

    

}

[展开全文]

 怎么遍历一个数组?

int[] temp = new int[5] { 5, 6, 7, 8, 9 };
for(int a = 0; a < 5;a++)
{
    Console.WriteLine(temp[a]);
}

2. foreach遍历数组:

int[] temp;
temp = new int[] { 5, 56, 7, 89, 23, 46, 459, 2, 77, 85, 65 };
foreach(int i in temp)
{
    Console.Write(i + " ");
}

i

[展开全文]

foreach(int temp in Array)

{

     Console.Write(temp+"" );

}

[展开全文]

foreach函数:遍历数组

int[] ddd = {11,22,33};

foreach(int temp in ddd)

{

}

数组的长度:ddd.Length;

[展开全文]

第八十四课  数组的遍历

1. 怎么遍历一个数组?

int[] temp = new int[5] { 5, 6, 7, 8, 9 };
for(int a = 0; a < 5;a++)
{
    Console.WriteLine(temp[a]);
}

2. foreach遍历数组:

int[] temp;
temp = new int[] { 5, 56, 7, 89, 23, 46, 459, 2, 77, 85, 65 };
foreach(int i in temp)
{
    Console.Write(i + " ");
}

int i 为临时变量,随着遍历的进行,i中的数值也是变化的,所以叫做临时变量。

foreach只能正序遍历,如果想倒序遍历数组可以用for或while循环语句来写。

3. 获得位置数组中数值的长度,也就是数值的个数。

int[] ages = {2,3,4,5,6,7,8,9};

Console.Write(ages.Length);

输出结果为:8   这样就可以获得数组中数值的个数了。

例如:

int[] temp;
temp = new int[] { 5, 56, 7, 89, 23, 46, 459, 2, 77, 85, 65 };
Console.WriteLine(temp.Length);
for(int i = 0; i < temp.Length; i++)
{
    Console.Write(temp[i] + " ");
}

temp.Length可以直接用,用以表示数组中数值的个数。

 

[展开全文]

用 foreach 快速遍历数组(但是只能正序)

先定义数组 int[] ages = {10, 20,12,20};

获取数组长度  ages.Length  代码

然后用for循环进行遍历(”适用于长度不固定的数组“)

for( int i = 0; i < ages . Length; i++)

{

}

 

[展开全文]

授课教师

SiKi学院老师

课程特色

下载资料(1)
视频(118)
图文(1)