Exemplo n.º 1
0
        static void Main(string[] args)
        {
            //创建一个边长为5的正方形对象
            Square s = new Square("正方形", 5);

            Console.WriteLine(s.ToString());

            //创建一个学生
            Student[] stu = new Student[4];
            stu[0] = new Student("090810116", "icecream", 'm', "cslg", "HuShan Road 99#");
            Console.WriteLine("学生1\n" + ((IStudent)stu[0]).Answer() + ((ISchool)stu[0]).Answer());

            stu[1] = new Student("090810124", "sjs", 'm');
            string result = ((IStudent)stu[1]).Answer();

            Console.WriteLine("学生2:\n" + result);


            //测试委托(degelate)
            Students c_s = new Students();

            c_s [0] = new Covariant_Student("张云翼", '男', "电子科大");
            c_s [1] = new Covariant_Student("张云翼", '男', "电子科大");
            c_s [2] = new Covariant_Student("张云翼", '男', "电子科大");
            c_s [3] = new Covariant_Student("张云翼", '男', "电子科大");
            c_s [4] = new Covariant_Student("张云翼", '男', "电子科大");

            PointPerson point = new PointPerson(c_s.getStudent);

            for (int i = 0; i < 5; i++)
            {
                Covariant_Person a = point(i);
                Console.WriteLine("姓名:{0}\t性别:{1}.", a.covariant_name, a.covariant_sex);
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            //创建一个边长为5的正方形对象
            Square s = new Square( "正方形",5);
            Console.WriteLine(s.ToString());

            //创建一个学生
            Student[] stu = new Student[4];
            stu[0] = new Student("090810116", "icecream", 'm', "cslg", "HuShan Road 99#");
            Console.WriteLine("学生1\n"+((IStudent)stu[0]).Answer()+((ISchool)stu[0]).Answer());

            stu[1] = new Student("090810124", "sjs", 'm');
            string result = ((IStudent)stu[1]).Answer();
            Console.WriteLine("学生2:\n"+result);


            //测试委托(degelate)
            Students c_s = new Students();
            c_s [0]=new Covariant_Student("张云翼",'男',"电子科大");
            c_s [1]=new Covariant_Student("张云翼",'男',"电子科大");
            c_s [2]=new Covariant_Student("张云翼",'男',"电子科大");
            c_s [3]=new Covariant_Student("张云翼",'男',"电子科大");
            c_s [4]=new Covariant_Student("张云翼",'男',"电子科大");

            PointPerson point = new PointPerson(c_s.getStudent);
            for(int i = 0; i < 5; i++)
            {
                Covariant_Person a = point(i);
                Console.WriteLine("姓名:{0}\t性别:{1}.",a.covariant_name,a.covariant_sex);
            }
        }
Exemplo n.º 3
0
        private void button1_Click(object sender, EventArgs e)
        {
            Students s = new Students();
            s[0] = new Student("张云翼", '男', "电子科大");
            s[1] = new Student("王海", '男', "成都东软");
            s[2] = new Student("陈若水", '女', "电子科大");
            s[3] = new Student("赵霞", '女', "电子科大");
            s[4] = new Student("梅岭", '女', "电子科大");

            PointPerson point = new PointPerson(s.getStudent);
            listBox1.Items.Clear();
            for (int i = 0; i < 5; i++)
            {
                Person a = point(i);
                listBox1.Items.Add("姓名:"+ a.covariant_name+"\t性别:"+ a.covariant_sex);
            }
        }
Exemplo n.º 4
0
        private void button1_Click(object sender, EventArgs e)
        {
            Students s = new Students();

            s[0] = new Student("张云翼", '男', "电子科大");
            s[1] = new Student("王海", '男', "成都东软");
            s[2] = new Student("陈若水", '女', "电子科大");
            s[3] = new Student("赵霞", '女', "电子科大");
            s[4] = new Student("梅岭", '女', "电子科大");

            PointPerson point = new PointPerson(s.getStudent);

            listBox1.Items.Clear();
            for (int i = 0; i < 5; i++)
            {
                Person a = point(i);
                listBox1.Items.Add("姓名:" + a.covariant_name + "\t性别:" + a.covariant_sex);
            }
        }
Exemplo n.º 5
0
        static void Main()
        {
            //创建学生集合并存入5个学生的信息
            Students s = new Students();

            s[0] = new Student("张云逸", '男', "电子科大成都学院");
            s[1] = new Student("王海", '男', "成都东软学院");
            s[2] = new Student("李若水", '女', "电子科大成都学院");
            s[3] = new Student("赵霞", '女', "电子科大成都学院");
            s[4] = new Student("梅岭", '男', "成都东软学院");

            //创建返回值为Person型的委托对象并指定引用Students集合的getStudent方法
            PointPerson point = new PointPerson(s.getStudent);

            for (int i = 0; i < 5; i++)
            {
                Person a = point(i);          //协变委托方法调用
                Console.WriteLine("姓名:{0}\t性别:{1}。", a.name, a.sex);
            }

            //创建人员集合并存入5个人的信息
            Persons p = new Persons();

            p[0] = new Person("许珊珊", '女');
            p[1] = new Person("尹佳云", '女');
            p[2] = new Person("周巍", '男');
            p[3] = new Person("杨森", '男');
            p[4] = new Person("刘通", '男');
            //创建参数为Student的委托对象,并指定引用Perons集合的getPos
            Position pos = new Position(p.getPos);
            int      k   = pos(new Student("周巍", '男', "电子科大成都学院")); //逆变委托方法调用

            Console.WriteLine("该生是第{0}个学生。", k + 1);


            Console.ReadKey();
        }