I’m studying for my MCPD and this example class is on shown in the ADO.net Entity Framework example. I haven’t encounter ? in the property such as OrderDate and EmployeeID Can someone please explain to me what it does or mean?
public class Order
{
public int OrderID { get; set; }
public string CustomerID { get; set; }
public int? EmployeeID { get; set; }
public DateTime? OrderDate { get; set; }
public DateTime? RequiredDate { get; set; }
public DateTime? ShippedDate { get; set; }
public int? ShipVia { get; set; }
public decimal? Freight { get; set; }
public string ShipName { get; set; }
public string ShipAddress { get; set; }
public string ShipCity { get; set; }
public string ShipRegion { get; set; }
public string ShipPostalCode { get; set; }
public string ShipCountry { get; set; }
public Customer Customer { get; set; }
}
It’s short for the type
Nullable<T>whereTis the type that precedes the?. Thusis equivalent to
Effectively, a nullable type allows you to assign
nullto value types. These types are very special as various operators and methods on the corresponding non-nullable type are “lifted” to the nullable type.Note that
Tmust be a non-nullable value type. Also, it’s a common misconception thatNullable<T>is a reference type. It is a value type, albeit a rather special one (it gets help from the compiler to be so special). For example, boxing and unboxing operations are treated very specially (the underlying value is boxed, unless it isnullin which case the boxed instance ofobjectis thenullreference; ifnullis unboxed to an instance of a nullable type, it is unboxed to the value whereHasValueisfalse).