首页 > Windows开发 > 详细

C#索引器

时间:2014-12-14 18:31:15      阅读:275      评论:0      收藏:0      [点我收藏+]
        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#索引器

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!