namespace 控制台
{
class Program
{
static void Main()
{
Person p = new Person();
p.GetResult();
p.GG();
Console.ReadKey();
}
}
class Person
{
List<int> list = new List<int>() { 0,1,2};
public IEnumerable<int> GetResult()
{
Console.WriteLine("李四");
foreach (int i in list)
{
yield return i;
}
}
public void GG()
{
Console.WriteLine("张三");
}
}
}
yield的特性 ------解决方案-------------------- 再说仔细一点吧
p.GetResult().GetEnumerator().MoveNext(); ------解决方案-------------------- 看编译后的代码 ------解决方案-------------------- 这个是典型的Deferred execution
"Deferred execution is supported directly in the C# language by the