实验报告四.doc
- 文档编号:1549032
- 上传时间:2022-10-23
- 格式:DOC
- 页数:9
- 大小:181.47KB
实验报告四.doc
《实验报告四.doc》由会员分享,可在线阅读,更多相关《实验报告四.doc(9页珍藏版)》请在冰豆网上搜索。
攀枝花学院实验报告
实验课程:
VisualC#.NET程序设计教程实验项目:
上机实验6实验日期:
2015.05.12
系:
数计学院成绩:
一、实验目的
1、初步掌握常用集合的创建和操作方法。
2、初步掌握索引器的定义和使用。
3、初步掌握泛型接口、泛型类、泛型属性和泛型方法的使用。
二、实验要求
1.熟悉VisualStudio.Net2010的基本操作方法。
2.认真阅读本章相关内容,尤其是案例。
3.实验前进行程序设计,完成源程序的编写任务。
4.反复操作,直到不需要参考教材、能熟练操作为止。
三、实验步骤
1、设计一个Windows应用程序,定义一个Teacher类,包含姓名和职称两个字段和一个输出自己信息的方法,并用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()
{
InitializeComponent();
}
publicclassTeacher
{
privatestringname;
privatestringjob;
publicTeacher(stringname,stringjob)
{
this.name=name;
this.job=job;
}
publicstringGetMessage()
{
returnstring.Format("姓名:
{0}\n职称:
{1}。
",this.name,this.job);
}
}
ArrayLista=newArrayList();
privatevoidShow()
{
foreach(objectbtObjina)
{
TeacherbtErgodic=(Teacher)btObj;
lblShow.Text+="\n"+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);
Teacherx=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)
{
lblShow.Text="";
Show();
}
}
}
运行结果如图所示:
2、设计一个Windows应用程序,定义一个Student类,包含学号和姓名两个字段,并定义一个班级类ClassList,该类包括一个Student集合,使用索引器访问该集合,实现与实例6_3类似的功能。
源程序如下:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
namespaceTest4_2
{
publicpartialclassForm1:
Form
{
publicForm1()
{
InitializeComponent();
}
publicclassStudent
{
privatestringnumber;
privatestringname;
publicStudent(stringnumber,stringname)
{
this.number=number;
this.name=name;
}
publicstringNumber
{
get
{
returnnumber;
}
}
publicstringName
{
get
{
returnname;
}
}
}
publicclassClassList
{
privateStudent[]student;
publicClassList(intx)
{
student=newStudent[x];
}
publicStudentthis[intindex]
{
get
{
if(index<0||index>=student.Length)
{
returnnull;
}
returnstudent[index];
}
set
{
if(index<0||index>=student.Length)
{
return;
}
student[index]=value;
}
}
publicStudentthis[stringget]
{
get
{
foreach(Studentsinstudent)
{
if(s.Name.IndexOf(get)!
=-1||s.Number.IndexOf(get)!
=-1)
returns;
}
returnnull;
}
}
}
ClassLista=newClassList(50);
privatevoidbtAdd_Click(objectsender,EventArgse)
{
intindex=Convert.ToInt32(txtFigure.Text)-1;
Students=newStudent(txtNumber.Text,txtName.Text);
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 实验 报告
![提示](https://static.bdocx.com/images/bang_tan.gif)