unity游戏开发-C#语言基础篇(事件)

class Program
    {
        static void Main(string[] args)
        {
             Boy boy = new Boy("汤姆","男",10,100);
            Girl girl = new Girl("珍妮", "女", 8, 888);


            Parent p = new Parent();

            p.myevent += boy.BoyCall;
            p.myevent += girl.GirlCall;
            p.DeteCall();


            Boy b1 = new Boy("汤姆", "男", 1, 100);
            Boy b2 = new Boy("汤姆", "男", 3, 100);
            Boy b3 = new Boy("汤姆", "男", 2, 100);
            Boy b4 = new Boy("汤姆", "男", 18, 100);
            Boy b5 = new Boy("汤姆", "男", 10, 100);

            List<Boy> list = new List<Boy>();
            list.Add(b1);
            list.Add(b2);
            list.Add(b3);
            list.Add(b4);
            list.Add(b5);

            for (int i = 0; i < list.Count; i++)
            {
                for (int j = i; j < list.Count; j++)
                {
                    if (list[i].Age > list[j].Age)
                    {
                        Boy temp = list[i];
                        list[i] = list[j];
                        list[j] = temp;

                    }
                }
            }


            foreach (var item in list)
            {
                item.BoyCall();
            }

            Console.ReadKey();
        }
      
    }
  class Parent
    {
        public delegate void mydete();
        public event mydete myevent;

        public void DeteCall()
        {
            Console.WriteLine("大人呼喊孩子们!");
            myevent();
        }
    }
class Girl
    {
        private string name;

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

        public int Age
        {
            get { return age; }
            set { age = value; }
        }
        private double proerty;

        public double Proerty
        {
            get { return proerty; }
            set { proerty = value; }
        }


        private string sex;

        public string Sex
        {
            get { return sex; }
            set { sex = value; }
        }

        public Girl(string _name, string _sex, int _age, double _proerty)
        {

            this.Name = _name;
            this.Sex = _sex;
            this.Age = _age;
            this.Proerty = _proerty;

        }
        public void GirlCall()
        {

            Console.WriteLine("我叫{0},我是{1}孩,今年{2}岁了,我有{3}元,我听到父母的喊声!", this.Name, this.Sex, this.Age, this.Proerty);
        }
    }
 class Boy
    {
        private string name;

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

        public int Age
        {
            get { return age; }
            set { age = value; }
        }
        private double proerty;

        public double Proerty
        {
            get { return proerty; }
            set { proerty = value; }
        }


        private string sex;

        public string Sex
        {
            get { return sex; }
            set { sex = value; }
        }
        public Boy(string _name, string _sex, int _age, double _proerty)
        {

            this.Name = _name;
            this.Sex = _sex;
            this.Age = _age;
            this.Proerty = _proerty;

        }

        public void BoyCall()
        {
            Console.WriteLine("我叫{0},我是{1}孩,今年{2}岁了,我有{3}元,我听到父母的喊声!", this.Name, this.Sex, this.Age, this.Proerty);
        }
    }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容