Tuesday, June 18, 2013

Nullable vs int?, C#

Today I generated code from the designer surface using DbContext template and realized that all of my nullable fields are declared as Nullable<int>. Kind of surprise to me "why it did not declare <int?>".

Found that both syntax are similar and there is no difference between the operation of two syntax. So feel free to use any one of them. They both represent an integer variable which can have null value too.

Mind, there is a difference between having a default value i.e. 0 or being null.

No comments:

Post a Comment