欢迎来到天天文库
浏览记录
ID:47850434
大小:181.47 KB
页数:9页
时间:2019-11-28
《实验报告四 Visual C#.NET程序设计教程》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、攀枝花学院实验报告实验课程:VisualC#.NET程序设计教程实验项目:上机实验6实验日期:2015.05.12系:数计学院成绩:一、实验目的1、初步掌握常用集合的创建和操作方法。2、初步掌握索引器的定义和使用。3、初步掌握泛型接口、泛型类、泛型属性和泛型方法的使用。二、实验要求1.熟悉VisualStudio.Net2010的基本操作方法。2.认真阅读本章相关内容,尤其是案例。3.实验前进行程序设计,完成源程序的编写任务。4.反复操作,直到不需要参考教材、能熟练操作为止。三、实验步骤1、设计一个Windows应用程序,定义一个Teacher类,包含姓名和职称两个字段和一个输出自己
2、信息的方法,并用ArrayList实现与实例6_1相同的功能。源程序如下:usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Collections;namespaceTest4_1{publicpartialclassForm1:Form{publicForm1(){Initia
3、lizeComponent();}publicclassTeacher{privatestringname;privatestringjob;publicTeacher(stringname,stringjob)-8-{this.name=name;this.job=job;}publicstringGetMessage(){returnstring.Format("姓名:{0}职称:{1}。",this.name,this.job);}}ArrayLista=newArrayList();privatevoidShow(){foreach(objectbtObjina){Tea
4、cherbtErgodic=(Teacher)btObj;lblShow.Text+=""+btErgodic.GetMessage();}}privatevoidbtAdd_Click(objectsender,EventArgse){Teacherx=newTeacher(txtName.Text,txtJob.Text);a.Add(x);lblShow.Text="";Show();}privatevoidbtInster_Click(objectsender,EventArgse){intIndex=Convert.ToInt32(txtIndex.Text);Teac
5、herx=newTeacher(txtName.Text,txtJob.Text);a.Insert(Index,x);lblShow.Text="";Show();}privatevoidbtDelete_Click(objectsender,EventArgse){intIndex=Convert.ToInt32(txtIndex.Text);a.RemoveAt(Index);lblShow.Text="";Show();}privatevoidbtErgodic_Click(objectsender,EventArgse)-8-{lblShow.Text="";Show();
6、}}}运行结果如图所示:1、设计一个Windows应用程序,定义一个Student类,包含学号和姓名两个字段,并定义一个班级类ClassList,该类包括一个Student集合,使用索引器访问该集合,实现与实例6_3类似的功能。源程序如下:usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespa
7、ceTest4_2{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}-8-publicclassStudent{privatestringnumber;privatestringname;publicStudent(stringnumber,stringname){this.number=number;this.name=name;}publicstringNumber{g
此文档下载收益归作者所有