yield-return

    2热度

    3回答

    我有以下方法: public IEnumerable<object> GetParameters(Context context) { yield return new[] { 1, 2, 3 }; } 当我遍历这个枚举: foreach (var parameter in GetParameters()) { // Do something here with pa

    2热度

    3回答

    我有下面的方法使用Yield Return从文件中读取大(> 1m)行文本。 private static IEnumerable<string> ReadLineFromFile(TextReader fileReader) { using (fileReader) { string currentLine; while ((curr

    2热度

    3回答

    我决定创建一个像游戏一样的内存,以用unity3d学习游戏开发。 玩家点击卡片后,游戏应等待2秒钟,然后再将卡片翻转回来。 yield return new WaitForSeconds(2) -statement应该是完美的,但它的作用是不执行任何函数行。 这里是我的代码: 此生成卡网格(带按钮),并调用一个函数来翻转卡,单击卡时。 Card card = grid[i, j]; if (G

    3热度

    3回答

    我正在练习删除二叉搜索树上的节点,并且使用空模式为空链接创建了一个特殊类型(NullNode),因此我可以将一些理想行为添加到“空”类型。 节点类型和Nullnode类型共享相同INode接口,其中包括递归方法。 的的inode接口包括IEnumerable的递归方法POR预购,序和后序遍历,但是我不想NullNode返回任何元素(通过产量return语句)。 我该怎么办? 我知道我可以使用一个不

    6热度

    2回答

    我的代码如下,通过创建素数列表并检查下列潜在素数是否可以被列表中的任何素数均匀整除,从而找到所有素数在number以下的素数。 我在努力学习yield return的来龙去脉。现在我有一个List<int> primes,我在函数内使用。但我通过yield return返回相同的数据。所以我的问题是 我可以从函数内部访问IEnumerable < int>,因为我正在创建它?所以我可以删除列表<

    0热度

    3回答

    我试图了解AsEnumerable()对我的数据的影响,当迭代它时。我有一个模拟内存列表。如果我foreach在它与先调用ToList(),这股势力的评价和我的打印输出看起来像这样(见代码在这个岗位的底部来解释输出): entering da yield return yield return yield return exiting da doing something to aaro

    17热度

    5回答

    为什么我们不能同时使用return和yield return? 例如,我们可以在下面有GetIntegers1和GetIntegers2,但不是GetIntegers3。 public IEnumerable<int> GetIntegers1() { return new[] { 4, 5, 6 }; } public IEnumerable<int> GetIntegers2

    3热度

    3回答

    我发现在open source project下面的方法: static IEnumerable<T> Cat<T>(T t) { yield return t; } 据我的理解,它不是别的,只是返回一个包含IEnumerable<T>t。如果我是对的,它就等于return new List<T>{t};,这里使用yield return的目的/优势是什么?如果我错了,我

    2热度

    5回答

    我有可以返回的项目列表或像这样如下(伪)单个项目的功能 IEnumerable<T> getItems() { if (someCondition.Which.Yields.One.Item) { List<T> rc = new List<T>(); rc.Add(MyRC); foreach(var i in rc) y

    4热度

    1回答

    ,我发现自己最近使用SemaphoreSlim类,限制在(大)的可并行操作的进度工作流资源: // The below code is an example of the structure of the code, there are some // omissions around handling of tasks that do not run to completion that sh