What means
int?
declaration?
Thank you,
Sergey
What means
int?
declaration?
Thank you,
Sergey
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
AlanPosted Nov 14, 2008, 10:03 AM
int? defines a nullable int.
This means an 'int' variable which, in addition to the usual integral values, can also be assigned the special value of 'null' which means it contains no value at all!
For example:
int? i = null; // i has no value, not even zero
i = 0; // i is now equal to zero
Any value type variable can be made nullable by including an '?' after its name.
double? d = null; // defines a nullable double with no value
This is actually a shorthand for a variable of the generic type System.Nullable where T is any value type. This structure has two properties:
1. 'HasValue' of type bool which defines whether the nullable type has a value or not.
2. 'Value' of type T which defines the value if it has one.
Notice that only value types can be nullable. This is because 'null' means something different in the case of reference types - namely that the variable doesn't currently refer to an object.
Nullable types are useful in database work remembering that a field within a database table may either have a value of some type or be empty.
Fahadjamal JamaluddinPosted Apr 10, 2019, 5:51 AM