MyArrayList
自定义ArrayList,知多点: 1.定义字段和属性区别。 2.const、static、readonly用法。 3.索引器的定义。 4.虚方法应用。 class MyArrayList { //容量 private const int _defaultCapacity = 4; //存放数组元素 private object[] _items; //数组大小 private int _size; //元素个数为0的数组状态 private static readonly object[] emptyArray = new object[0]; public MyArrayList() { this._items = emptyArray; } public MyArrayList( int capacity) { if (capacity<0) { throw new ArgumentOutOfRangeException("capacity","ArrayList的容量不可为负数!"); } this._items = new object[capacity]; } //索引器 public virtual object this[int index] { get { if (index<0||index>=this._size) { throw new