阳光石油网|石油技术交流|石油人论坛

 找回密码
 欢迎注册
查看: 1003|回复: 2

[基本理论] 建模中数据查询理论

[复制链接]
  • TA的每日心情
    慵懒
    2012-11-8 10:13
  • 签到天数: 15 天

    [LV.4]偶尔看看III

    发表于 2016-2-21 21:21:36 | 显示全部楼层 |阅读模式

    马上注册,下载丰富资料,享用更多功能,让你轻松玩转阳光石油论坛。

    您需要 登录 才可以下载或查看,没有账号?欢迎注册

    x

    迭代器可用于遍历列表和数组之类的集合。

    迭代器方法或 get 访问器对集合的自定义迭代。 迭代器方法使用 Yield (Visual Basic) 或 将返回 (c#) 语句依次返回每个元素。

    Yieldyield return 语句时,代码的当前位置确保。

    在下一次迭代器函数时,执行从该位置进行重新启动。

    您使用来自客户端代码中的迭代器使用 对于每个 for each…next (Visual Basic) 或 foreach (c#) 使用 LINQ 查询,语句或。

    在下面的示例中,For Eachforeach 循环的第一个迭代在直到第一 Yield 的 SomeNumbers 迭代器方法会导致执行或 yield return 语句为止。此迭代返回值为 3,以及迭代方法的当前位置保留。在循环的下一个迭代,在迭代器方法的执行从延续它将会停止,再次停止的位置,并在到达 Yieldyield return 语句时。此迭代返回值为 5,以及迭代方法的当前位置再次保存。在迭代器方法结束时,循环完成。

    static void Main(){    foreach (int number in SomeNumbers())    {        Console.Write(number.ToString() + " ");    }    // Output: 3 5 8    Console.ReadKey();}public static System.Collections.IEnumerable SomeNumbers(){    yield return 3;    yield return 5;    yield return 8;}那么这个迭代器方法
    静态的IEnumerable 接口类,他指包含一个GetEnumerator()方法,方法SomNumbers也就是说,返回的是yield return3是一个接口类。


    foreach(int number in SomeNumbers){console.writeline(number.ToString()+" ");}
    //output:3 5 8console.readkey();

    [size=12.800000190734863px]An iterator can be used to step through collections such as lists and arrays.

    [size=12.800000190734863px]An iterator method or get accessor performs a custom iteration over a collection.An iterator method uses the Yield (Visual Basic) oryield return (C#) statement to return each element one at a time.When a Yield or yield return statement is reached, the current location in code is remembered.Execution is restarted from that location the next time the iterator function is called.

    [size=12.800000190734863px]

    [size=12.800000190734863px]一个迭代器方法执行集合内的自定义迭代

    [size=12.800000190734863px]一个迭代器方法使用Yield或yield return语句一次返回一个元素

    [size=12.800000190734863px]迭代器可以被用来在集合内步进,如lists和arrays,譬如list和数组

    [size=12.800000190734863px]Yield或yield return语句被打倒,当前位置被记录。

    [size=12.800000190734863px]public override IEnumerable<ModuleReference> Modules
            {
                get
                {
                    // Please fill this method with your modules with lines like this:
                    //yield return new ModuleReference(typeof(Module));
                    yield return new ModuleReference(typeof(HelloModule));
                    yield return new ModuleReference(typeof(HelloModule2));
                }
            }

    [size=12.800000190734863px]

    [size=12.800000190734863px]我们看这个例子,返回类型是IEnumerable<ModuleReference>,其中包含get方法

    yield return

  • TA的每日心情

    2016-5-22 10:12
  • 签到天数: 44 天

    [LV.5]常住居民I

    发表于 2016-2-22 18:38:58 | 显示全部楼层
    赞一个 挺不错的
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    无聊
    2017-2-26 17:13
  • 签到天数: 301 天

    [LV.8]以坛为家I

    发表于 2016-2-29 19:51:26 | 显示全部楼层
    回复 支持 反对

    使用道具 举报

    您需要登录后才可以回帖 登录 | 欢迎注册

    本版积分规则

    QQ|Archiver|手机版|小黑屋|阳光石油网 ( 鲁ICP备2021003870号-1 )

    GMT+8, 2024-5-5 16:56 , Processed in 0.066895 second(s), 20 queries .

    Powered by Discuz! X3.4 Licensed

    Copyright © 2001-2021, Tencent Cloud.

    快速回复 返回顶部 返回列表