• 仿照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());
    }

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



     

  • 相关阅读:
    怎么加载用户自定义控件
    一个C#委托的示例
    signed add
    避免QuartusII中将没有进行定义的信号自动生成wrie类型
    serial_to_parallel
    用modelsim仿真——对文件的操作
    base of logic
    blocking PK nonblocking
    parallel to serial
    使用signalTapII看综合掉的wrie和register的值
  • 原文地址:https://www.cnblogs.com/shikyoh/p/2246519.html
Copyright © 2020-2023  润新知