using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {
        public static void Main(string[] args)
        {
            Student[] stu = new Student[3];
            stu[0] = new Student("张三",23);
            stu[1] = new Student("李四",34);
            Stus stus = new Stus();
            stus.students = stu;
            Console.WriteLine(stus[1].age);
        }              
    }


    public class Student
    {
        public string name;
        public int age;
        public Student(string name, int age)
        {
            this.name = name;
            this.age = age;
        }
    }

    public class Stus
    {
        public Student[] students;
        public Student this[int index]
        {
            get
            {
                return students[index];
            }
        }
        public Student this[string name]
        {
            get
            {
                for (int i = 0; i < students.Length; i++)
                {
                    if (students[i].name == name)
                    {
                        return students[i];
                    }
                }
                return null;
            }
        }
    }

}

posted on 2010-08-09 18:47  aparche  阅读(246)  评论(0编辑  收藏  举报