2

I've got a pretty noob question for ya. I keep seeing this syntax:

<%= Html.LabelFor(model => model.Email) %>

...and I have no idea what the => means. I thought it was syntax for linq2sql or ado.net entity framework but I'm just using straight ado.net. I don't understand why the VWD used that syntax when generating the Create form.

What does => mean?

John Farrell
  • 24,673
  • 10
  • 77
  • 110
quakkels
  • 11,676
  • 24
  • 92
  • 149
  • possible duplicate of [How do I pronounce "=>" as used in lambda expressions in .Net](http://stackoverflow.com/questions/274022/how-do-i-pronounce-as-used-in-lambda-expressions-in-net) – Daniel Auger May 27 '10 at 20:35

2 Answers2

8

it is a lambda expression it means "goes to"

this is a pretty good link for explaining here

the left side is the input the right side the expression or statement block, here you are calling the LabelFor method inputing model and using the Email field on the model passed in.

Pharabus
  • 6,081
  • 1
  • 26
  • 39
  • Why wouldn't it just write the line as Html.LabelFor(Model.Email)? – quakkels May 27 '10 at 19:22
  • 1
    @quakkels because the signature for LabelFor takes an expression as its only parameter not a string, this allows you to pass in a lambda expression to define the field to use rather than the value of the field, this means LabelFor can use attributes defined on the field – Pharabus May 27 '10 at 19:31
1

Take a look at Lambda Expressions (C# Programming Guide)

All lambda expressions use the lambda operator =>, which is read as "goes to". The left side of the lambda operator specifies the input parameters (if any) and the right side holds the expression or statement block. The lambda expression x => x * x is read "x goes to x times x."

SQLMenace
  • 132,095
  • 25
  • 206
  • 225