zoukankan      html  css  js  c++  java
  • 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;
    }
    }
    }
  • 相关阅读:
    继承 多态
    封装练习
    PHP 面向对象封装
    面向对象 类和对象
    PHP前端和数据库的连接
    数组2
    PHP数组
    正则表达式
    PHP字符串
    linux基础
  • 原文地址:https://www.cnblogs.com/shikyoh/p/2113875.html
Copyright © 2011-2022 走看看