题主要的代码如下,
using System;
using System.Collections.Generic;
using System.Linq;
public class Demo
{
class Person
{
public string Name { get; set; }
public int Age { get; set; }
public Person(string Name, int Age) {
this.Name = Name;
this.Age = Age;
}
public void GetInfo()
{
Console.WriteLine($"{Name}\t{Age}");
}
}
class Student : Person
{
public string stuNumber { get; set; }
public Student(string Name, int Age, string stuNumber) : base(Name, Age)
{
this.stuNumber = stuNumber;
}
public new void GetInfo()
{
Console.WriteLine($"{Name}\t{Age}\t{stuNumber}");
}
}
class Teacher : Person
{
public string Title{ set; get; }
public Teacher(string Name, int Age, string Title) : base(Name, Age)
{
this.Title = Title;
}
public new void GetInfo()
{
Console.WriteLine($"{Name}\t{Age}\t{Title}");
}
}
class Tuor : Teacher
{
public string Course { get; set; }
public Tuor(string Name, int Age, string Title,string Course) : base(Name, Age, Title)
{
this.Course = Course;
}
public new void GetInfo()
{
Console.WriteLine($"{Name}\t{Age}\t{Title}\t{Course}");
}
}
static void Main()
{
var person = new Person("张三", 18);
person.GetInfo();
var student = new Student("李四", 20, "No1");
student.GetInfo();
var teacher = new Teacher("王五", 32, "副教授");
teacher.GetInfo();
var tuor = new Tuor("王麻子", 45, "叫兽", "博士研究生课程");
tuor.GetInfo();
Console.ReadKey();
}
}
有帮助或启发麻烦点下
【采纳该答案】,谢谢~~有其他问题可以继续交流~