“收益回报"的名称是什么?概念? IEnumerable,迭代器,生成器? [英] What is the name of the "yield return" concept? IEnumerable, Iterator, Generator?

查看:85
本文介绍了“收益回报"的名称是什么?概念? IEnumerable,迭代器,生成器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

yield return概念的正式名称是什么?

What exactly is the official name of the yield return concept?

public IEnumerable<T> Bar() {
    ...
    yield return foo;
    ...
}

我听说(读过)它被称为:

I've heard(read) it being referred to as:

  • 迭代器
  • IEnumerabe
  • 发电机
  • <您的选择>

迭代器不只是在某个事物上进行迭代的某些事物"吗? List<T> IEnumerable<T>,因此似乎也不合理.

Isn't an iterator just some "thing" that iterates over something? A List<T> is an IEnumerable<T>, so doesn't seem reasonable as well.

关于SO的许多答案都使用这两个术语之一.

A lot of answers here on SO that talk about yield return use one of these two terms.

那发电机"呢?还是仅在您凭空创造出价值"时才适用,例如您不需要数据收集的斐波那契数字吗?

What about "generators"? Or does that only apply when you're "conjuring up values out of thin air", e.g. the Fibonacci Numbers where you don't need a data collection as a source?

推荐答案

作为非语言特定方式的一般概念,生成器"可能是最常见的术语.如果我要与不熟悉C#的人交谈,那将是我要使用的.

As a general concept in a non-language specific way, "generator" is probably the most common term. That's what I'd use if I were talking to someone who wasn't familiar with C#.

该方法本身是C#规范术语中的 iterator .该实现是一个 iterator块.

The method itself is an iterator in C# specification terminology. The implementation is an iterator block.

根据C#4规范的第10.14节:

From section 10.14 of the C# 4 spec:

使用 iterator块(§8.2)实现的功能成员(§7.5)称为 iterator .

A function member (§7.5) implemented using an iterator block (§8.2) is called an iterator.

这是我在专门谈论C#时要使用的术语.

That's the terminology I'd use when talking about C# specifically.

这篇关于“收益回报"的名称是什么?概念? IEnumerable,迭代器,生成器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆