C#中索引器实例

     class Name 
    {
           
        private string[] names;
        public int lenth;
        private int _index;
        public Name(int lenth)
        {

            this._index=0;
            this.lenth=lenth;
            names = new string[this.lenth];

        }
        public object this[int index]
        {
            set
            {
                if (index>=0&&index<this.lenth)
                {
                    names[index] =(string) value;
                }
            }
            get
            {
                if (index>=0&&index<this.lenth)
                {


                    return names[index];
                }
                return "";
            }
        }

    }

  

posted @ 2013-03-27 23:34  Predator  阅读(155)  评论(0编辑  收藏  举报