• 第六章,上机练习3


     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 using System.Threading.Tasks;
     6 
     7 namespace SJ3_4
     8 {
     9     class Program
    10     {
    11         static void Main(string[] args)
    12         {
    13             List<Employee> empls = new List<Employee>();
    14             SE Joe=new SE("杰克",20,100);
    15             SE ai = new SE("艾边成", 25, 200);
    16             PM pm = new PM("艾斯", 30, 10);
    17             empls.Add(Joe);
    18             empls.Add(ai);
    19             empls.Add(pm);
    20             //foreach (Employee item in empls)
    21             //{
    22             //      Console.WriteLine(item.SayHi());
    23             //}
    24             for (int i = 0; i < empls.Count; i++)
    25             {
    26                 Console.WriteLine(empls[i].SayHi());
    27             }
    28         }
    29     }
    30 }
     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 using System.Threading.Tasks;
     6 
     7 namespace SJ3_4
     8 {
     9     public class Employee
    10     {
    11         //姓名
    12         public string Name { get; set; }
    13         public int Age { get; set; }
    14         public virtual string SayHi() 
    15         {
    16             string message = string.Format("大家好");
    17             return message;
    18         }
    19         /// <summary>
    20         /// 构造函数
    21         /// </summary>
    22         public Employee(string name,int age) 
    23         {
    24             this.Name = name;
    25             this.Age = age;
    26         }
    27     }
    28 }
     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 using System.Threading.Tasks;
     6 
     7 namespace SJ3_4
     8 {
     9     /// <summary>
    10     /// 经理类
    11     /// </summary>
    12     public class PM:Employee
    13     {
    14         //管理经验
    15         public int YesarOfExperience { get; set; }
    16         //构造函数
    17         public PM(string name, int age, int yesarOfExperience): base(name, age)
    18         {
    19             this.YesarOfExperience = yesarOfExperience;
    20         }
    21         public override string SayHi() 
    22         {
    23             string message;
    24             message = string.Format("大家好,我是{0},今年{1},管理经验是{0}", this.Name, this.Age, this.YesarOfExperience);
    25             return message;
    26         }
    27     }
    28 }
     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 using System.Threading.Tasks;
     6 
     7 namespace SJ3_4
     8 {
     9     /// <summary>
    10     /// 程序员类
    11     /// </summary>
    12     public class SE:Employee
    13     {
    14         //人气
    15         public int Popularity { get; set; }
    16         public SE(string name, int age, int popularity) : base(name,age) 
    17         {
    18             this.Popularity = popularity;
    19         }
    20         /// <summary>
    21         /// SayHi
    22         /// </summary>
    23         /// <returns></returns>
    24         public override string SayHi() 
    25         {
    26             string message;
    27             message= string.Format("大家好,我是{0},今年{1},人气是{0}", this.Name, this.Age, this.Popularity);
    28             return message;
    29         }
    30     }
    31 }
  • 相关阅读:
    node之body-parser的使用
    node解决跨域问题
    node之post提交上传
    HDU 6397(容斥原理)
    HDU 3374(最小最大表示法+KMP)
    HDU 6396(优先队列+思维)
    HDU 6395(矩阵快速幂)
    HDU 6370(并查集)
    HDU 6356(线段树)
    HDU 6354(计算几何)
  • 原文地址:https://www.cnblogs.com/yjjh/p/6691741.html
Copyright © 2020-2023  润新知