傻大方


首页 > 知识库 > >

数组|数组和集合ppt课件


按关键词阅读: 集合 数组 课件 PPT

1、数组和集合对象,2,目标,使用System.Array 对象 理解集合对象的特点和优点 使用System.ArrayList 对象 使用哈希表对象,3,int score1;
System.Console.ReadLine(score1) int score2;
System.Console.ReadLine(score2) int score3;
System.Console.ReadLine(score3) int score4;
System.Console.ReadLine(score4) int score5;
System.Console.ReadLine(score5) int。

2、score6;
System.Console.ReadLine(score6) int score7;
System.Console.ReadLine(score7),第七位学生的分数,第六位学生的分数,第五位学生的分数,第四位学生的分数,第三位学生的分数,第二位学生的分数,第一位学生的分数,score 6,score 5,score 4,score 3,score 1,score 0,score 2,System.Array 简介 3-1,应用程序,数 组,存储学员的分数,int score = new int7;
,6,7,5,4,3,2,1,在数组的术语中 , 元素表示数组中存储的值 , 数组长度 。

3、指数组中存储的值的总数 , 数组秩指数组的总维数,4,System.Array 简介 3-2,数组定义:数据类型 数组名称;
,int MyArray = 1,2,3,4,5,6,7;
,MyArray0, MyArray1, MyArray2MyArray6,MyArray 0 = 604,可以执行各种操作 , 如存储、检索、排序和反转,System . Array,如何简易地执行对数组的操作?,5,System.Array 简介 3-3,System.Array,Array是抽象的基类 , 提供 CreateInstance 方法来创建数组,Array obj = Array.CreateInstance 。

4、(typeof(string),10);
,6,System.Array 的属性和方法,属性,Length,方法,BinarySearch,Clear,Copy,Rank,IsReadOnly,IsFixedSize,CopyTo,CreateInstance,GetLength,GetLowerBound,GetUpperBound,GetValue,IndexOf,LastIndexOf,Reverse,SetValue,Sort,7,示例 2-1,static void Main(string args) /构建 objNames 数组 Array objNames = Array.Cre 。

【数组|数组和集合ppt课件】5、ateInstance (typeof(string),5);
/初始化值 objNames.SetValue(“A,0);
objNames.SetValue(“B,1);
objNames.SetValue(“C,2);
objNames.SetValue(“D,3);
objNames.SetValue(“E,4);
Console.WriteLine(“数组值);
for(int ctr = 0 ;
ctr 5;
ctr+) Console.WriteLine(“元素 0: 1,ctr+1, objNames.GetValue(ctr);
,使用 GetValue() 方法检索数组值, 。

6、使用 SetValue() 方法存储字符串,将 objNames 实例化为字符串对象并且其中存放 5 个元素,8,示例 2-2,Console.WriteLine(“n数组中元素的总数是 0,objNames.Length.ToString();
/输出数组秩 Console.WriteLine(n数组秩是 0,objNames.Rank.ToString();
/反转数组并输出 Array.Reverse(objNames);
Console.WriteLine(“n反转数组后);
for(int ctr = 0 ;
ctr 5;
ctr+) Console.WriteLine(“元素 0: 。

7、 1,ctr+1, objNames.GetValue(ctr);
,显示 objNames数组的长度,显示 objNames数组秩,反转数组元素,反转后的数组元素列表,课堂练习: 这段代码用For Each结构怎么写?,9,思考和演示,使用: int A = 1,2,3,4,5,6 和使用: B.CreateInstance (typeof(string),5) 创建的数组 , A可以使用B所有的属性和方法吗?,教员演示两种数组的差别,10,System.Collections 简介 2-1,ID,工作档案,ID,工作档案,ID,工作档案,ID,工作档案,职员 2,职员 4,Employee 对 。

8、象的集合,对象组中元素个数未知 , 并且随时可能要循环、添加和移除,System.Collection,11,System.Collections 简介 2-2,System.Collection 命名空间,12,Hashtable,Hashtable 类,将人名引用为 Hash(或键)并将电话号码引用为值,Hashtable objFriendDetails = new Hashtable();
,13,使用哈希表对象,教员演示使用哈希表的例子程序,14,ArrayList 类 2-1,数组灵活性,Array 类的容量或元素数是固定的 , 而 ArrayList 类的容量可以根据需要动态扩展 。
通过设置 。

9、ArrayList.Capacity 的值可以重新分配内存和复制元素 使用 ArrayList 提供的方法可以同时添加、插入或移除一个范围内的元素,可以设置数组的下界 数组可以有多个维 许多需要使用数组的实例都可以使用ArrayList,ArrayList的特点,15,ArrayList 类 2-2,16,简单的例子,ArrayList List = new ArrayList();
/给数组增加10个Int元素 for( int i=0;
i10;
i+ ) List.Add(i);
/.程序做一些处理 /将第6个元素移除 List.RemoveAt(5);
/再增加3个元素 for( int。

10、i=0;
i3;
i+ ) List.Add(i+20);
/返回ArrayList包含的数组 Int32 values = (Int32)List.ToArray(typeof(Int32);
,17,使用ArrayList对象,教员演示使用ArrayList的例子程序,18,总结,多数编程语言都提供数组这种数据结构 , 用以存储属于相同类型的多个数据元素 可以使用 Array 类的 CreateInstance 方法来创建Array对象 , 也可以直接定义数组对象 集合可用于管理在运行时动态创建的元素项 System.Collections 命名空间提供一组接口和类 , 让用户可以对一组数据元素执行各种集合操作 用户可以通过 HashTable 类将数据、键值作为一组来存储 , 这些数据是根据键值进行组织的 Array 类属于 System 命名空间 , 而 ArrayList 类属于 System.Collections 命名空间 ArrayList在Array的基础上提供了动态的特性 。


来源:(未知)

【学习资料】网址:/a/2021/0326/0021779734.html

标题:数组|数组和集合ppt课件


上一篇:文件编号三种方法|文件编号三种方法ppt课件

下一篇:教师|教师个人教科研工作总结