zoukankan      html  css  js  c++  java
  • 仿照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());
    }

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



     

  • 相关阅读:
    用户和组管理
    权限管理
    文件查找
    文件管理 2
    文件管理
    2016多校训练3_1007(hdu5758 Explorer Bo)
    poj3334(Connected Gheeves)
    POJ1015-Jury Compromise
    使用python来访问Hadoop HDFS存储实现文件的操作
    微信H5自动播放音乐,视频解决方案
  • 原文地址:https://www.cnblogs.com/shikyoh/p/2246519.html
Copyright © 2011-2022 走看看