代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MyArrayList
{
public class MyArrayList
{
//容量
private const int _defaultCapacity = 4;
//存放数组元素
private object[] _items;
//数组大小
private int _size;
//元素个数为0的数组状态
private static readonly object[] emptyArray = new object[0];
/// <summary>
/// 析构函数(为了不引发未将对象引用到实例,所以对_items赋值)
/// </summary>
public MyArrayList()
{
this._items = emptyArray;
}
public MyArrayList(int capacity)
{
if(capacity<0)
throw new ArgumentOutOfRangeException("capacity","ArrayList的容量不可为负数");
this._items = new object[capacity];
}
/// <summary>
/// 索引器
/// </summary>
//