;  else
    {
    while (innercount ﹤ index)
    {
    first = first.next;
    innercount++;
    }
    return first.data;
    }
    }
    //在指定的索引上插入新的元素
    public void InsertAtIndex(int index,T data)
    {
    int innercount = 1;
    MyListNode first = this.firstNode;
    if (index ﹥ count)
    {
    throw new Exception("Index out of boundary");
    }
    if (index == 1)
    {
    this.firstNode = new MyListNode(data);
    this.firstNode.next = first;
    }
    else
    {
    while (innercount ﹤ index - 1)
    {
    first = first.next;
    innercount++;
    }
    MyListNode newNode = new MyListNode(data);
    newNode.next = first.next;
    first.next = newNode;
    }
    this.count++;
    }
    //C# 泛型集合-删除指定索引上的集合元素
    public void RemoveAtIndex(int index)
    {
    int innercount = 1;
    MyListNode first = this.firstNode;
    if (index ﹥ count)
    {
    throw new Exception("Index out of boundary");
    }
    if (index == 1)
    {
    this.firstNode = first.next;
    }
    else
    {
    while (innercount ﹤ index - 1)
    {
    first = first.next;
    innercount++;
    }
    first.next = first.next.next;
    }
    this.count--;
    }
    //C# 泛型集合-删除集合中的所有元素
    public void RemoveAll()
    {
    this.firstNode = null;
    this.count = 0;
    }
    //为实现该集合类能用foreach进行遍历
    public IEnumerator GetEnumerator()
    {
    MyListNode first = this.firstNode;
    while (first!= null)
    {
    yield return first.data;
    first = first.next;
    }
    }
    //内部节点类
    private class MyListNode
    {
    public T data { get; set; }//节点上的元素值