Working with Nulls in C# Flashcards Preview

.NET / C# > Working with Nulls in C# > Flashcards

Flashcards in Working with Nulls in C# Deck (12)
Loading flashcards...
1

What is a nullable type in C#?

Are instances of Nullable which represents the T value plus the "variation" of null.

2

What is the shorthand of Nullable?

T?
e.g: int?

3

What is the default value of the Nullable when not set?

null

4

What does the HasValue return when null?

false, if not null the return is true.

5

What does the Value method return, what happens when it is null?

The underlying value... exception when null

6

How does comparison of nullable types work?

As expected... no surprises.

7

What happens when you try to define a nullable int to a regular int?

compilation issue... you need to typecast or get is value.

8

What are the 3 null-checking operators? Do

1 - ? true : false
2 - ?? executed when null
3 - ?. and ?[

9

What is the null object pattern?

It is a software design pattern to reduce the ammount of null references.

10

Why using the null object pattern?

- Reduce the amount of runtime null exceptions.
- Reduce the amount of repetitive null checking. Therefore simplifying production code.

11

How to implement the null object pattern?

By implementing a dummy interface that does nothing.

12

What are the dangers of protect null code too much?

Can hide exceptions and make throubleshooting harder. Not used for error handling!!!