Practice mode C#

What is int? in C#?

Correct answer B. Shorthand for Nullable<int>, an int that can also hold null

Explanation

T? for a value type T is shorthand for System.Nullable, a struct that holds a value plus a HasValue flag. So int? can be any int or null, which is useful for optional database columns. It is still a value type, not a heap wrapper. Reading .Value when HasValue is false throws InvalidOperationException, so use GetValueOrDefault or ?? instead.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.