每日一记

    技术2022-05-20  52

    namespace ConsoleApplication1{    abstract class Person    {        private int age;

            public int Age        {            get { return age; }            set { age = value; }        }        private string name;

            public string Name        {            get { return name; }            set { name = value; }        }        private string sex;

            public string Sex        {            get { return sex; }            set { sex = value; }        }        public abstract void SayHello();    }}

    namespace ConsoleApplication1{    class Teacher:Person    {        private int gongling;

            public int Gongling        {            get { return gongling; }            set { gongling = value; }        }        public override void SayHello()        {            Console.WriteLine("我是{0}年龄{1}工龄{2}性别{3}", Name, Age, gongling, Sex);        }    }}namespace ConsoleApplication1{    class Program    {        static void Main(string[] args)        {            List<Person> list = new List<Person>();            Student st1=new Student{Name="张三",Age=11,Aihao="擦擦擦擦擦玻璃",Sex="男"};            Teacher th1=new Teacher{Name="李四",Age=11,Gongling=222,Sex="女"};            list.Add(st1);            list.Add(th1);            foreach (Person people in list)         {                people.SayHello();         }        }    }}今天学习的方法重载,就今天的学习,使我更清楚明白这个的用法和功能。


    最新回复(0)