IEnumerable中运用yield

 protected void Page_Load(object sender, EventArgs e)
{
var temp
= Getreturn();
var temp1
= temp.ToList();//返回List<string> 5条数据
temp.All(o =>//调用 Getreturn()中的for循环数据
{
Response.Write(o);
return true;
});
Getreturns().All(o
=>
{
//o的类型为 IEnumerable<string>
return true;
});
//Response.Write(Getreturn());
}
public IEnumerable<string> Getreturn()
{
for (int i = 0; i < 5; i++)
{
yield return "wode";
}
}
public IEnumerable<IEnumerable<string>> Getreturns()
{
List
<string> list = new List<string>();
list.Add(
"wode");
list.Add(
"wode1");
for (int i = 0; i < 5; i++)
{
yield return list;
}
}
}
原文地址:https://www.cnblogs.com/shikyoh/p/2113875.html