int[,] nVisited ={
{1,2,3},
{4,5,6},
{7,8,9}
};
// Use "for" to loop two-dimension array(使用for循环二维数组)
Console.WriteLine("User 'for' to loop two-dimension array");
for (int i = 0; i < nVisited.GetLength(0); i++)
for (int j = 0; j < nVisited.GetLength(1); j++)
Console.Write(nVisited[i, j]);
Console.WriteLine();
//Use "foreach" to loop two-dimension array(使用foreach循环二维数组)
Console.WriteLine("User 'foreach' to loop two-dimension array");
foreach (var item in nVisited)
Console.Write(item.ToString());
int[][] nVisited = new int[3][];
nVisited[0] = new int[3] { 1, 2, 3 };
nVisited[1] = new int[3] { 4, 5, 6 };
nVisited[2] = new int[6] { 1, 2, 3, 4, 5, 6 };
//Use "foreach" to loop two-dimension array(使用foreach循环二维数组)
Console.WriteLine("User 'foreach' to loop two-dimension array");
foreach (var item in nVisited)
foreach (var val in item)
Console.WriteLine(val.ToString());
int[] val = { 1, 2, 3 };
ArrayList list = new ArrayList();
list.AddRange(val);
foreach (int item in list)//在循环语句中指定当前正在循环的元素的类型,不需要进行拆箱转换
{
Console.WriteLine((2*item));
}
Console.WriteLine();
for (int i = 0; i < list.Count; i++)
{
int item = (int)list[i];//for循环需要进行拆箱
Console.WriteLine(2 * item);
}
using (IEnumerator<T> enumerator = collection.GetEnumerator())
{
while (enumerator.MoveNext())
{
this.Add(enumerator.Current);
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有