static void Main(string[] args)
{
foreach (var arg in GetStrings())
{
Console.WriteLine(arg);
}
Console.ReadLine();
}
static IEnumerable<string> GetStrings()
{
yield return "1";
Console.WriteLine("1返回去了");
yield return "2";
Console.WriteLine("2返回去了");
yield return "3";
Console.WriteLine("3返回去了");
}
执行结果:
1
1返回去了
2
2返回去了
3
3返回去了
标签:返回,return,yield,WriteLine,arg,集合,Console
From: https://www.cnblogs.com/sunhouzi/p/17856579.html