索引器

 class Program
    {
        static void Main(string[] args)
        {
            IndexClass a = new IndexClass();
            a[0] = "张三";
            a[1] = "李四";
            a[2] = "王五";
            Console.WriteLine("a[0]=" + a[0]);
            Console.WriteLine("a[1]=" + a[1]);
            Console.WriteLine("a[2]=" + a[2]);
            Console.ReadKey();
        }
    }
    class IndexClass
    {
        private string[] name = new string[10];
        public string this[int index]
        {
            get { return name[index]; }
            set { this.name[index] = value; }
        }
    }
posted @ 2019-04-14 14:54  夜静春山  阅读(122)  评论(0)    收藏  举报