- 4
- 0
- 约4.35千字
- 约 15页
- 2016-09-25 发布于湖北
- 举报
精品ppt课件清华大学原版c#学习资料第4章数组坪.ppt
第四章 数组 目标 数组的定义 声明和操作一维和二维数组 交错数组和多维数组 简单的排序方法 体验 首先产生一个包含有12个随机数的数组,然后分别计算出数组中的最大值、最小值。最后程序将显示整个随机数数组。随机数的范围是1—100之间。 数组 3-1 数组是同一数据类型的一组值 数组属于引用类型,因此存储在堆内存中 数组元素初始化或给数组元素赋值都可以在声明数组时或在程序的后面阶段中进行 语法: 数据类型 数组名称; int[] arrayHere; 数组 78 (0) 67 (1) 89 (2) 92 (3) 66 (4) Joe Tom Lee Jim Bill 23.5 18.9 27.3 21.4 29.6 学生分数的整数数组 职员姓名的字符串数组 室温的浮点数组 数组位置 数组 static void Main(string[] args) { int count; Console.WriteLine(请输入您要登记的学生人数 ); count=int.Parse(Console.ReadLine()); // 声明一个存放姓名的字符串数组,其长度等于提供的学生人数 string[] names = new string[count]; // 用一个 for 循环来接受姓名 for(int i=0; icount; i++) { Console.WriteLine(“请输入学生 {0} 的姓名 ,i+1); names[i]=Console.ReadLine(); } Console.WriteLine(已登记的学生如下: ); // 用 foreach 循环显示姓名 foreach(string disp in names) { Console.WriteLine({0}, disp); } } 数组声明 初始化数组元素的循环 显示输出的循环 一维数组 声明并初始化 int[] array1 = new int[5] { 1, 3, 5, 7, 9 }; string[] weekDays = new string[] { Sun, Mon, Tue, Wed, Thu, Fri, Sat }; int[] array2 = { 1, 3, 5, 7, 9 }; string[] weekDays2 = { Sun, Mon, Tue, Wed, Thu, Fri, Sat }; 声明一个数组变量但不将其初始化 int[] array3; array3 = new int[] { 1, 3, 5, 7, 9 }; // OK //array3 = {1, 3, 5, 7, 9}; // Error 多维数组 声明数组 int[,] array6 = new int[10, 10]; 声明数组时将其初始化 int[,] array2D = new int[,] { { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 } }; int[, ,] array3D = new int[,,] { { { 1, 2, 3 } }, { { 4, 5, 6 } } }; 声明一个数组变量但先不将其初始化 int[,] array5; array5 = new int[,] { { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 } }; // OK //array5 = {{1,2}, {3,4}, {5,6}, {7,8}}; // Error 也可以给数组元素赋值,例如: array5[2, 1] = 25; 交错数组3-1 交错数组是数组的元素为数组的数组 6 2 3 5 交错数组声明 int[][] jaggedArray = new int[4][]; 交错数组初始化 jaggedArray[0] = new int[6]; jaggedArray[1] = new int[2]; jaggedArray[2] = new int[3]; jaggedArray[3] = new int[5]; 交错数组3-2 例如: jaggedArray[0] = new int[] { 1, 3, 5, 7, 9,13 }; jaggedArray[1] = new int[] { 0, 2, }; jaggedArray[2] = new int[] { 5,11, 22 }; jaggedArray[3] = new int[] { 3,5,7,10, 32 }; 还可以在声明数组时将其初始化,如: int[][] jaggedArray2 = new
您可能关注的文档
最近下载
- ^DLINK交换机还原用户名密码.doc VIP
- 8年级上册生物期末测试卷.doc VIP
- 投融资部2025年工作总结及2025年工作计划.docx VIP
- 内江市2022-2023学年七年级上学期期末地理试题.docx VIP
- 补骨脂主要成分的肝毒性比较研究.docx VIP
- 2024年全国职业院校技能大赛中职组(法律实务赛项)考试题库-下(多选、判断题汇总).docx
- 江苏省无锡市惠山区2024-2025学年九上化学期末质量检测模拟试题含解析.doc VIP
- 2026年春统编版(新教材)小学道德与法治三年级下册(全册)教学设计(附教材目录P97).pdf
- 2012年全国高考(江苏卷)物理试题及解答.pdf VIP
- 加州驾照笔试模拟题中文版300题目加答案版.docx
原创力文档

文档评论(0)