-2

I have started learning MVC and I run into some unclear lines. Here is the link for the tutorial: The Tutorial Link
So the problem is with the part of Strongly Typed Models and the @model Keyword
This is the first thing I did not understand:

public ActionResult Details(int? id)
{...}

1. The first line of this method, I didn't really understood what does the ?(question mark) symbolize and what does it mean ?

And the other thing is here:

@Html.DisplayNameFor(model => model.Title)

2.And for this line, my question is what is that => used for ?

Thank You.

bustrama
  • 61
  • 1
  • 9
  • 7
    Those are not MVC specific, but C# language features. You need to look at [Nullable types](https://msdn.microsoft.com/en-us/library/1t3y8s4s.aspx) and [Lambda expressions](https://msdn.microsoft.com/en-us/library/bb397687.aspx) – Cristian Lupascu Mar 05 '15 at 14:10
  • Also a duplicate of: http://stackoverflow.com/questions/167343/c-sharp-lambda-expression-why-should-i-use-this – George Stocker Mar 05 '15 at 14:15

2 Answers2

2

The question mark indicates that the type is nullable

The => is part of a lambda statement

David Watts
  • 2,249
  • 22
  • 33
2

1) The ? on int? means it's a nullable int, i.e. an int cannot normally be null, but a nullable int can.

When you use it inside an Action parameter it is basically making the parameter optional.

2) The => is part of a lambda expression / statement which is not easily explained, see this MSDN article

model => model.Title

Basically means with the model, use the Title attribute and pass the Title to the DisplayNameFor method.

Paul Zahra
  • 9,522
  • 8
  • 54
  • 76