“="如何发音?用于 .Net 中的 lambda 表达式 [英] How do I pronounce "=>" as used in lambda expressions in .Net
问题描述
我很少遇到其他程序员!
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 预发布论坛上问了这个问题,Anders Hejlsberg 回应说
In fact, I asked this very question on the official linq pre-release forums, and Anders Hejlsberg responded by saying
我通常将 => 运算符读作becomes"或for which".例如,
Func f = x => x * 2;
Func test = c => c.City == "London";
读作x 变为 x * 2"和c.City 等于伦敦的 c"
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.
在给某人阅读代码的情况下,比如说,通过电话,那么只要他们是 C# 程序员,我只会使用lambda"这个词 - 即p lambda p dot age大于十六."
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."
在评论中,Steve Jessop 在转换的情况下提到了映射到"——所以以安德斯的例子为例:
In comments Steve Jessop mentioned 'maps to' in the case of transformations - so taking Anders' example:
x => x * 2;
会读
x 映射到 x 乘以 2.
x maps to x times 2.
在这种情况下,这似乎更接近于代码的实际意图,而不是变成".
That does seem much closer to the actual intention of the code than 'becomes' for this case.
这篇关于“="如何发音?用于 .Net 中的 lambda 表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!