码迷,mamicode.com
首页 > Windows程序 > 详细

C#索引器

时间:2014-12-14 18:31:58      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   ar   color   sp   on   div   log   

        private T[] _list;
        public void Init(int maxCapcity = 100)
        {
            if (maxCapcity <= 0) throw new ArgumentException("maxCapcity无效");
            _maxCapcity = maxCapcity;
            _list = new T[maxCapcity];
        }

        private int _length;
        public int Lenght
        {
            get { return _length; }
        }

        private int _maxCapcity;
        public int MaxCapcity
        {
            get { return _maxCapcity; }
        }

        public T this[int index]
        {
            get
            {
                if (index >= Lenght) throw new IndexOutOfRangeException("index");
                return _list[index];
            }
            set
            {
                if (index >= MaxCapcity) throw new IndexOutOfRangeException("index");
                _list[index] = value;
            }
        }

 

C#索引器

标签:style   blog   io   ar   color   sp   on   div   log   

原文地址:http://www.cnblogs.com/GuoJinPangZi/p/4162761.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!