The ? operator signifies that the value type immediately preceding the operator may have the value null.
One way to think of it, and by no means a formal definition, is its an "exception" to how the value would "normally" be assigned a value.
A classic use case of the operator is in a simple controller in a web app. Suppose we have a typical DB that stores a list of movies. We can access the details of these movies by adding into the URL the following:
.../Movies/Details?MovieName=TopGun
, or,
.../Movies/Details?MovieName=DieHard
But what if we wanted to see the details of a movie where the value of MovieName is not defined? What will you show on your HTML page? Well, this controller will notify us of a bad request:
Check this out:
// GET: Movies/Details/5
public ActionResult Details(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Movie movie = db.Movies.Find(id);
if (movie == null)
{
return HttpNotFound();
}
return View(movie);
}
nullable
tag beside you don't know what is?
mean? – Tyrolienne