using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace 深入.NET_第六章{ public class SE:Employee { public SE(string id,string name,int age,Gender gender,int popularity) :base(id,age,name,gender) { this.ID = id; this.Name = name; this.Age = age; this.Gender = gender; this.Popularity = popularity; }public SE() { } private int _popularity; public int Popularity { get { return _popularity; } set { _popularity = value; } } public string SayHi(){ string message = string.Format("大家好,我是{0},今年{1}岁,我的人气值是{2}。", this.Name, this.Age, this.Popularity); return message; } }}
namespace 深入.NET_第六章{ public class Employee { public Employee() { Console.WriteLine("父类无参对象构造执行"); } public Employee(string id, int age, string name, Gender gender) { this.ID = id; this.Age = age; this.Name = name; this.Gender = gender; } protected string ID { get; set; } protected int Age { get; set; } protected string Name { get; set; } protected Gender Gender { get; set; } }}
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace 深入.NET_第六章{ public enum Gender { 男,女 }}
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace 深入.NET_第六章{ public class PM:Employee { public PM(string id, string name, int age, Gender gender, int yearOfExperience) { this.ID = id; this.Name = name; this.Age = age; this.Gender = gender; this.YearOfExperience = yearOfExperience; } public PM() { } private int _yearOfExperience; public int YearOfExperience { get { return _yearOfExperience; } set { _yearOfExperience = value; } } public string SayHi(){ string message = string.Format("大家好,我是{0},今年{1}岁,项目管理经验{2}年。", base.Name, base.Age, this.YearOfExperience); return message; } }}
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace 深入.NET_第六章{ class Program { static void Main(string[] args) { SE se = new SE("112","艾边成",25,Gender.男,100); Console.WriteLine(se.SayHi()); PM pm = new PM("520", "苏苏", 20, Gender.女, 10); Console.WriteLine(pm.SayHi()); Console.ReadLine(); } }}
0 0