仿照List<T>写的集合类。

 public class SLList<T> : IEnumerator
{
private ArrayList Info;
private int Index;
public SLList(IEnumerable<T> List)
{
Index = -1;
Info = new ArrayList(List.Count());
foreach (var item in List)
{
Info.Add(item);
}
}
public SLList()
{
Index = -1;
Info = new ArrayList();
}
public SLList(int Size)
{
Index = -1;
Info = new ArrayList(Size);
}

public void Add(T item)
{
Info.Add(item);
}
public object Current
{
get
{
return Info[Index];
}
}
public void Reset()
{
Index = -1;
}
public bool MoveNext()
{
Index++;
return Index >= Info.Count ? false : true;
}
public IEnumerator GetEnumerator()
{
return (IEnumerator)this;
}


}

用法:

  List<int> list = new List<int>();
list.Add(1);
list.Add(2);
list.Add(3);
list.Add(4);
list.Add(5);
SLList<int> newcl = new SLList<int>(list);
foreach (var item in newcl)
{
Console.WriteLine(item);
}

SLList<string> stringlist = new SLList<string>();
// stringlist.Add
stringlist.Add("我是");
stringlist.Add("LCC");
stringlist.Add("Shikyoh");
foreach (var item in stringlist)
{
Console.WriteLine(item.ToString());
}

实现方式,可能需要优化。但现在暂时没想好。待续 待续。。。。。。



 

原文地址:https://www.cnblogs.com/shikyoh/p/2246519.html