As others have mentioned, ?
is used for declaring a value type as nullable.
This is great in a couple of situations:
- When pulling data from a database that has a null value stored in a nullable field (that maps to a .NET value type)
- When you need to represent "not specified" or "not found".
For example, consider a class used to represent feedback from a customer who was asked a set of non-mandatory questions:
class CustomerFeedback
{
string Name { get; set; }
int? Age { get; set; }
bool? DrinksRegularly { get; set; }
}
The use of nullable types for Age
and DrinksRegularly
can be used to indicate that the customer did not answer these questions.
In the example you cite I would take a null
value for LastLogon
to mean that the user has never logged on.