What is the difference between 'int' and 'int?'. For example:
public int? GoalPR { get; set; } public int AnchorPR { get; set; } The int? is a nullable type, so the type that can be also null.
The main reason of introduction of this kind of types for value types, is fluent support for DataBase systems, where value: can be, can be absent and can be null.
There are actually 3 states.
So your code that interacts with the data received and sent to DB smoothly handles that kind of situations having possibility for its own value types assume null value too.
Take a look at the documentation for Nullable<T>.
int? is just syntactic sugar for Nullable<int>
int? can be null.
int can't.
That's (pretty much) the only difference.
int? field could see torn reads and writes. See this question for example.x = someOperations + x and so on. And if you aren't using Interlocked there then you have a problem.
int?is anullable int, which allows the value to be null.intandint?is exactly the same as the difference betweenintandNullable<int>.int?is merely a short-hand forNullable<int>o_O