Flashcards in Working with Nulls in C# Deck (12)
What is a nullable type in C#?
Are instances of Nullable which represents the T value plus the "variation" of null.
What is the shorthand of Nullable?
What is the default value of the Nullable when not set?
What does the HasValue return when null?
false, if not null the return is true.
What does the Value method return, what happens when it is null?
The underlying value... exception when null
How does comparison of nullable types work?
As expected... no surprises.
What happens when you try to define a nullable int to a regular int?
compilation issue... you need to typecast or get is value.
What are the 3 null-checking operators? Do
1 - ? true : false
2 - ?? executed when null
3 - ?. and ?[
What is the null object pattern?
It is a software design pattern to reduce the ammount of null references.
Why using the null object pattern?
- Reduce the amount of runtime null exceptions.
- Reduce the amount of repetitive null checking. Therefore simplifying production code.
How to implement the null object pattern?
By implementing a dummy interface that does nothing.