博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
深入.NET平台和C#编程.第五章:上机练习2 - 3
阅读量:6553 次
发布时间:2019-06-24

本文共 5885 字,大约阅读时间需要 19 分钟。

------------------------------------------Employee类------------------------------------------

1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6  7 namespace Employment 8 { 9     public class Employee10     {11         //年龄12         public int Age { get; set; }13 14         //性别15         public Gender Gender { get; set; }16 17         //工号18         public string ID { get; set; }19 20         //姓名21         public string Name { get; set; }22 23         //给Employee类添加工作列表属性24         protected List
WorkList { get; set; }25 26 //构造函数27 public Employee(string id , int age , Gender gender , string name , List
list)28 {29 this.Age = age;30 this.Gender = gender;31 this.ID = id;32 this.Name = name;33 this.WorkList = list;34 }35 36 //虚方法37 public virtual string SayHi()38 {39 string ss = this.Name;40 return ss;41 }42 43 44 }45 }
View Code

------------------------------------------formMyOffice窗体-------------------------------------

1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Threading.Tasks; 9 using System.Windows.Forms;10 11 namespace Employment12 {13     public partial class formMyOffice : Form14     {15         public formMyOffice()16         {17             InitializeComponent();18         }19 20         //采用泛型集合List保存内容21         List
empls = new List
();22 23 ///
24 /// 窗口加载25 /// 26 ///
27 ///
28 private void formMyOffice_Load(object sender, EventArgs e)29 {30 List
list1 = new List
();31 list1.Add(new Job("编码", "购物车模块"));32 list1.Add(new Job("测试","给购物车模块做单元测试"));33 SE ai = new SE("112" , "刚刚" , 25 , Gender.男 , 100 , list1);34 35 List
list2 = new List
();36 list2.Add(new Job("设计", "数据库模块"));37 list2.Add(new Job("编写文档", "详细设计说明书"));38 SE joe = new SE("113", "菲菲", 22, Gender.女, 200, list2);39 40 PM pm = new PM("890" , "康康" , 30 , Gender.男 , 50 , null);41 empls.Add(ai);42 empls.Add(joe);43 empls.Add(pm);44 }45 46 ///
47 /// 员工汇报工作48 /// 49 ///
50 ///
51 private void button1_Click(object sender, EventArgs e)52 {53 54 foreach (Employee item in empls)55 {56 57 MessageBox.Show(item.SayHi());58 //if (item is PM)59 //{60 // MessageBox.Show(((PM)item).DoWork(),"汇报");61 //}62 //if (item is SE)63 //{64 // MessageBox.Show(((SE)item).DoWork(),"汇报");65 //}66 }67 }68 69 70 71 }72 }
View Code

------------------------------------------Gender类---------------------------------------------

1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6  7 namespace Employment 8 { 9     //枚举性别10     public enum Gender11     {12         男,13         女14     }15 }
View Code

------------------------------------------Job类-------------------------------------------------

1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6  7 namespace Employment 8 { 9     public class Job10     {11         //工作名称12         public string Name { get; set; }13 14         //描述15         public string Description { get; set; }16 17         //构造函数18         public Job(string name , string description)19         {20             this.Name = name;21             this.Description = description;22         }23 24 25     }26 }
View Code

------------------------------------------PM类--------------------------------------------------

1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6  7 namespace Employment 8 { 9     public class PM:Employee10     {11         //属性12         public int YearOfExperience { get; set; }13 14         //虚方法15         public override string SayHi()16         {17             string message = this.Name + ":管理员工完成工作内容!";18             return message;19         }20 21         //修改PM类的构造函数22         public PM(string id , string name , int age , Gender gender , int yearOfExperience , List
list):base(id , age , gender , name , list)23 {24 this.YearOfExperience = yearOfExperience;25 }26 27 28 }29 }
View Code

------------------------------------------SE类--------------------------------------------------

1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6  7 namespace Employment 8 { 9     public class SE:Employee10     {11         //属性12         public int Popularity { get; set; }13 14         //虚方法15         public override string SayHi()16         {17             StringBuilder sb = new StringBuilder();18             sb.Append(this.Name + ":\n");19             for (int i = 0; i < this.WorkList.Count; i++)20             {21                 sb.Append((i + 1) + "," + WorkList[i].Name + ":" + WorkList[i].Description + "\n");22             }23             return sb.ToString();24         }25 26         //修改SM类的构造函数27         public SE(string id , string name , int age , Gender gender , int popularity , List
list):base(id , age , gender , name , list)28 {29 this.Popularity = popularity;30 }31 32 33 }34 }
View Code

------------------------------------------运行结果-----------------------------------------------

转载于:https://www.cnblogs.com/chenhui666/p/6691787.html

你可能感兴趣的文章
newlisp 注释生成文档
查看>>
MySQL float 与decimal 各中的区别。
查看>>
PHP中set_magic_quotes_runtime()和get_magic_quotes_gpc()
查看>>
The sound of silence引发的关于互联网以及教育的利弊思考
查看>>
普华永道全球CEO报告:巴西企业家对未来预期改善
查看>>
自制Kindle电子书转化的实用技巧
查看>>
PyCon 2018:Facebook如何在4年间全面转向Python3?
查看>>
Flutter 布局(三)- FittedBox、AspectRatio、ConstrainedBox详解
查看>>
OkHttp 知识梳理(3) OkHttp 之缓存基础
查看>>
React Native填坑之旅--Stateless组件
查看>>
技术沙龙|区块链商用落地的策略与技术坑-区块链扩展和Fabric商用(杭州)
查看>>
java读写文件大全
查看>>
Spring的常用注解
查看>>
我的友情链接
查看>>
java 防止 XSS 攻击的常用方法总结
查看>>
我的友情链接
查看>>
java.lang.OutOfMemoryError总结
查看>>
IIS下虚拟主机的四种使用方法
查看>>
如何修改redhat7.2的ROOT密码
查看>>
腾讯技术工程 | 腾讯AI Lab解析2017 NIPS三大研究方向,启动教授及学生合作项目...
查看>>