C#数组练习代码
2008-01-11 18:58
417 查看
using System;
class Test
...{
static void Main()
...{
int[] arr = new int[] ...{ 1, 2, 3 };
for (int i = 0; i < arr.Length; i++)
...{ // 大括号可要可不要
Console.WriteLine(arr[i]);
}
}
}
using System;
class Test
...{
static void Main()
...{
int[] arr = ...{ 1, 2, 3 };
for (int i = 0; i < arr.Length; i++)
...{
Console.WriteLine(arr[i]);
}
}
}
using System;
class Test
...{
static void Main()
...{
int[] arr = new int[3] ;
arr[0]=1;
arr[1]=2;
arr[2]=3;
for (int i = 0; i < arr.Length; i++)
...{
Console.WriteLine(arr[i]);
}
}
}
using System;
class Test
...{
static void Main()
...{
int[] arr = new int[3] ;
arr[0]=1;
arr[1]=2;
arr[2]=3;
foreach (int i in arr)
...{
Console.WriteLine(i);
}
}
}
以上三组代码,运行效果是一样的。
下面看看动态数组
using System;
class SetArray
...{
public void PrintArr(int ArrLength)
...{
int[] arr = new int[ArrLength];
for (int i = 0; i < arr.Length; i++)
...{
arr[i] = i;
}
Console.WriteLine("Print Array's value");
for (int i = 0; i < arr.Length; i++)
...{
Console.WriteLine("arr[{0}]={1}", i, arr[i]);
}
}
}
class Test
...{
static void Main()
...{
SetArray arr = new SetArray();
int i = 1;
while (i > 0)
...{
Console.WriteLine("Please enter the array's length");
i = Int32.Parse(Console.ReadLine());
arr.PrintArr(i);
}
}
}
相关文章推荐
- 【C代码练习18】在数组中寻找某个数字
- 代码练习 简单文件读写 字符串 数组的处理 list Dictionary
- 指针与数组代码练习
- Java数组学习练习3冒泡排序数组代码
- Java 基础一些代码练习笔记(Array数组)
- 【C代码练习23】用指针寻找数组中的最大值和最小值
- 8.17 课堂练习代码,循环与数组
- Java 基础一些代码练习笔记(数组复制)
- PHP-自己写的代码练习-数组
- 数组练习
- IIS6.0日志文件分析代码_1生成访问字段记录到数组中
- 比较新旧两个数组值得增加和删除的JS代码
- 《C++ Primer Plus(第6版)》编程练习代码 Chapter 2
- 编写安全代码:数组和指针的本质以及何时不能互换
- 数组,个人练习,0928
- 编程练习:合并两个数组(包括三种快排程序)
- C#练习——统计整型数组中不重复数字的个数、将普通日期格式转换成汉字日期格式、在控制台录入每个学生的姓名,当用户输入quit(不区分大小写)时,程序停止接受用户的输入,并且显示出用户输入的学生的个数
- 用java代码将数组元素顺序颠倒
- c++ byte类型数组转十六进制字符串的几种代码实现
- FASM练习代码