|
|
1
16
Yield return会自动为您创建一个枚举器。 http://msdn.microsoft.com/en-us/library/9k7k7cf0.aspx 所以你可以这样做
它允许您快速创建一个对象集合(枚举器),您可以在其中循环并检索记录。yield return语句处理为您创建枚举器所需的所有代码。 yield return语句的主要部分是,在将集合返回给调用方法之前,不必加载集合中的所有项。它允许 lazy loading 何时使用 Yield Return . |
|
2
5
让 想了解更多信息,我可以查看justinetherage的博客 has a great article explaining more advanced usages of yield . |
|
|
3
1
|
|
|
5
0
This is a pretty good example of how it can simplify your code and clarify your intent . 至于在哪里使用它,在页面上需要迭代集合的任何地方,都可以使用返回IEnumerable的方法来代替List/Dictionary/etc。 |