怎么读" =>"如用于拉姆达EX pressions在.net拉姆、GT、QUOT、net

2023-09-02 10:17:58 作者:余生只护你一人

我很少满足任何其他程序员!

I very rarely meet any other programmers!

我想,当我第一次看到令牌是暗示,因为这就是它会读它作为一个数学证明但这显然不是它的意义。

My thought when I first saw the token was "implies that" since that's what it would read it as in a mathematical proof but that clearly isn't its sense.

所以,我怎么说或阅读=>,如: -

So how do I say or read "=>" as in:-

IEnumerable<Person> Adults = people.Where(p => p.Age > 16)

还是有甚至称这商定的方式?

Or is there even an agreed way of saying it?

推荐答案

我常说'使'阅读该运算符时。

I usually say 'such that' when reading that operator.

在你的榜样,P => p.Age> 16读作P,使得p.Age大于16。

In your example, p => p.Age > 16 reads as "P, such that p.Age is greater than 16."

其实,我问在官方LINQ pre-论坛发布过这个问题,和安德斯Hejlsberg为回应说

In fact, I asked this very question on the official linq pre-release forums, and Anders Hejlsberg responded by saying

我经常读=>运算符为成为或为其。例如,   Func键F = X => X * 2;   Func键测试= C => c.City ==伦敦;   读为X变为x * 2和c为其c.City相当于伦敦

I usually read the => operator as "becomes" or "for which". For example, Func f = x => x * 2; Func test = c => c.City == "London"; reads as "x becomes x * 2" and "c for which c.City equals London"

至于'去' - 这是从来没有对我有意义。 P是不会去任何地方。

As far as 'goes to' - that's never made sense to me. 'p' isn't going anywhere.

在阅读code的情况下给别人,比方说,在电话中,那么只要他们是老乡C#程序员,我只是用这个词'拉姆达' - 那就是P拉姆达p点的年龄大于十六条。

In the case of reading code to someone, say, over the phone, then as long as they're a fellow C# programmer, I'd just use the word 'lambda' - that is, "p lambda p dot age greater-than sixteen."

在评论史蒂夫·杰索普的转变的情况下提到的映射 - 所以服用Anders的例子:

In comments Steve Jessop mentioned 'maps to' in the case of transformations - so taking Anders' example:

x => x * 2;

会读

X映射到x次2。

这似乎更接近的code中的实际意图,而不是'变成'这种情况。

That does seem much closer to the actual intention of the code than 'becomes' for this case.