Advertisements

How to pronounce “=>” in lambda expressions?

I usually say ‘such that’ when reading that operator.

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

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

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”

As far as ‘goes to’ – that’s never made sense to me. ‘p’ isn’t going anywhere.

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.”

In comments Steve Jessop mentioned ‘maps to’ in the case of transformations – so taking Anders’ example:

x => x * 2;

would read

x maps to x times 2.

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

 

Source:

Answer by Erik Forbes  @stackoverflow.com

 

.NET Economics I understood

Advertisements

Prashant Pandya View All →

I am a full-stack engineer whose passion lies in building great products while enabling others to perform their roles more effectively. I have architect and built horizontally scalable back-ends; distributed RESTful API services; and web-based front-ends with modern, highly interactive Ajax UIs.

I deal with:

Techniques
Web applications
Distributed architecture
Parsers, compilers
Mobile First, Responsive design
Test-driven development

Using technologies :

+ASP.NET,C#,VB.NET,C++,MS SQL,ADO.NET,WCF ,MVC,Web API
+Java, JAX-RS, JavaScript, Node.js
+Ajax, JSON, HTML5, CSS3
+Mac OS X, Linux, Windows
+Android,iOS
+PhoneGap

My Qualities ,I believe :

Self-directed and passionate
Meticulous yet pragmatic
Leadership skills, integrity

Leave a Reply

%d bloggers like this: