日期:2014-05-17 浏览次数:21042 次
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
namespace yield_learn
{
public class person : System.Collections.IEnumerable
{
#region IEnumerable
public string x = "cc";
public System.Collections.IEnumerator GetEnumerator()
{
yield return "1";
Thread.Sleep(3000);
yield return "2";
Thread.Sleep(3000);
yield return "3";
Thread.Sleep(3000);
yield return "4";
Thread.Sleep(3000);
yield return "5";
Thread.Sleep(3000);
yield return "6";
}//是如何选择遍历哪个的??
public System.Collections.IEnumerator getnum()
{
yield return "dshdjs";//为什么没有输出这个??
}
#endregion
}
class Program
{
static void Main(string[] args)
{
person arrperson = new person();
foreach (string s in arrperson)//遍历一个类中的string吗,必须带有System.Collections.IEnumerator的才遍历,但是为什么第二个不遍历呢?
{
System.Console.WriteLine(s);
}
System.Console.ReadLine();
}
}
}