对数组的每个元素仍是数组的遍历方法,c#,foreach,for
来源:互联网 发布:诺维茨基职业生涯数据 编辑:程序博客网 时间:2024/05/17 20:26
数组的每一个元素仍是数组的遍历方法:
(1)foreach遍历,静态的,只能遍历,读取数据,不能更改值;
static void Main(string[] args)
{
int[][] arr5 = new int[3][];//定义三个内元素,即5个元素都是一个数组,,,
arr5[0] = new int[4]; //定义第一个元素的数组包含4个元素;
arr5[1] = new int[2];
arr5[2] = new int[3];
foreach (int[] i in arr5)//遍历外面再遍历里面,int[] 类型的i
{
foreach (int j in i)
{
Console.WriteLine(j);
}
}
Console.WriteLine("********");
Console.ReadKey();
}
(2)for 语句循环遍历,可对值进行改值。
static void Main(string[] args)
{
int[][] arr5 = new int[3][];//定义三个内元素,NULL第一个
arr5[0] = new int[4]; //定义
arr5[1] = new int[2];
arr5[2] = new int[3];
for (int i = 0; i < arr5.Length; i++)//注意.Length,而非GetLength
{
for (int j = 0; j < arr5[i].Length; j++)
{
Console.WriteLine( arr5[i][j] );
}
}
Console.WriteLine("********");
Console.ReadKey();
}
- 对数组的每个元素仍是数组的遍历方法,c#,foreach,for
- 数组遍历for与foreach的区别
- PHP foreach是如何遍历数组的?
- c 标签中的foreach遍历list数组时怎么取出数组元素的下标
- foreach遍历数组的两种方法
- foreach遍历二维数组的方法
- forEach方法遍历数组
- Shell循环遍历每个元素都是变量的数组
- php数组的遍历讲解 for foreach list each key
- php数组的遍历讲解 for foreach list each key
- 取ds的行数,FOR数组遍历,没有用foreach
- for与foreach遍历二维数组的语法区别
- php数组的遍历讲解 for foreach list each key
- php数组的遍历讲解 for foreach list each key
- 三中遍历数组和集合的方法 for foreach iterator
- foreach遍历数组中的元素
- 遍历数组删除某元素的方法
- PHP遍历数组的方法汇总——foreach
- Eclipse中编辑xml文件不自动提示怎么办?
- spring3.1.1 spring mvc 和mybatis3框架整合配置
- 漂亮的servlet-acquire cookies
- Android持续集成——lint
- 广度优先搜索(breadth_first search)
- 对数组的每个元素仍是数组的遍历方法,c#,foreach,for
- HDU 3988 Harry Potter and the Hide Story(数论)(素数筛法)
- svn创建搭建教程
- C++迷宫问题(BFS)
- Activity跳转Flag详解
- Django中连接Mysql报错 No module named MySQLdb
- 多用类型常量,少用#define预处理指令
- 第4课:Spark Streaming的Exactly-One的事务处理和不重复输出彻底掌握
- xin10下Genymotion无法拖拽的问题