//c#中实现自己的索引器,使用foreach遍历自定义类中的某个属性
using System.Collections;
using UnityEngine;
public class testA:IEnumerable {
string[] strAttr = new string[4];
public testA()
{
strAttr[0] = "zhans";
strAttr[1] = "lishi";
strAttr[2] = "wangwu";
strAttr[3] = "zhaoliu";
}
public IEnumerator GetEnumerator()
{
return new testB(strAttr);
}
}
public class testB:IEnumerator
{
testA tes = new testA();
private string[] Names;
int index = -1;
int StartIndex=0;
public testB(string []name)
{
Names = name;
}
public testB(string []name,int _StartIndex)
{
Names = name;
Start