标签:length eset cat generic stat pac var 数组 ati
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
string[] strl = { "1","2","3","4"};
People<string> s = new People<string>(strl);
foreach (var item in s)
{
Console.WriteLine(item);
}
}
}
public class People<T> : IEnumerable
{
private T[] _People;
//List<T> _arryList
public People(T[] _ArryList)
{
_People = new T[_ArryList.Length];
for (int i = 0; i < _ArryList.Length; i++)
{
_People[i] = _ArryList[i];
}
}
//实现接口方法
public IEnumerator GetEnumerator()
{
return new EnumeratorItem<T>(_People);
}
}
//这个泛型得到People泛类型、得到实例化
public class EnumeratorItem<T> : IEnumerator
{
public T[] _PeopleList;
int position = -1;
public EnumeratorItem(T[] _itemList)
{
_PeopleList = new T[_itemList.Length];
_PeopleList = _itemList;
}
public object Current
{
get
{
try
{
//返回该当前数组项
return _PeopleList[position];
}
catch (Exception)
{
throw;
};
}
}
public bool MoveNext()
{
position++;
return (position < _PeopleList.Length);
}
public void Reset()
{
position = -1;
}
}
}
标签:length eset cat generic stat pac var 数组 ati
原文地址:http://www.cnblogs.com/1ddd/p/6228750.html