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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
AlanRank #669 · 3.6K reputationPosted Nov 14, 2008, 5:03 AM EST
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 JamaluddinRank #3,157 · 454 reputationPosted Apr 10, 2019, 1:51 AM EDT