Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why such hype with C# lambda functions? [duplicate]

Tags:

c#

lambda

I'm beginning to program in C# 2.0, so I have never used lambda expressions, but, why so much fuss about it? Are them just syntactic sugar around anonymous delegates, or is there something more which I can't see?

like image 724
raven Avatar asked Jul 20 '09 17:07

raven


People also ask

Will taking vitamin C help my skin?

Vitamin C can also help fend off the signs of aging because of its vital role in the body's natural collagen synthesis. It helps to heal damaged skin and, in some cases, reduces the appearance of wrinkles. Adequate vitamin C intake can also help repair and prevent dry skin.

Is L-ascorbic acid safe?

The U.S. Food and Drug Administration (FDA) states that ascorbic acid is a generally recognized as safe (GRAS) substance for use as a chemical preservative in foods and as a nutrient or dietary supplement.

Can ascorbic acid penetrate skin?

Furthermore, the introduction of a stable preparation of L-ascorbic acid is now available that can penetrate the skin and deliver L-ascorbate to the epidermis and dermis.

What percentage of vitamin C should you use?

Concentration: The sweet spot for the concentration level is between 10 and 20 percent. You definitely want a concentration that's higher than 8 percent for maximum effectiveness.


2 Answers

Well, lambda expressions have two main things over anonymous methods:

  • They're more concise than anonymous methods
  • They can be converted to expression trees as well as delegates

Unless you're using expression trees, they're extremely similar to anonymous methods though. The difference is that often you can write several lambda expressions in one statement (chaining method calls together) without losing readability, but anonymous methods are just a bit too wordy.

By the way, it's not so much that lambda expressions are "just syntactic sugar around anonymous delegates" as that both lambda expressions and anonymous methods are "just syntactic sugar around creating delegates (and expression trees)."

Don't discount syntactic sugar though - the benefits of anonymous functions acting as closures is massive, along with the ability to have the code right where you want it, instead of in a separate method.

like image 162
Jon Skeet Avatar answered Sep 18 '22 16:09

Jon Skeet


They can easily be used as just syntax sugar around a delegate but the big thing about lambdas is that the compiler has the ability turn them into expression trees which open up many possibilities (not the least of which being LINQ).

like image 44
Andrew Hare Avatar answered Sep 18 '22 16:09

Andrew Hare