C#索引器

        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#索引器

上一篇:windows8及以后系统中启动之前的虚拟机提示Not enough physical memory解决办法


下一篇:C# 类:类型 , 数学:类型