From the course: C# Essential Training 1: Types and Control Flow
Unlock the full course today
Join today to access over 23,200 courses taught by industry experts.
Using nullable types - C# Tutorial
From the course: C# Essential Training 1: Types and Control Flow
Using nullable types
- [Instructor] Because we're working with a nullable of a type that nullable actually has some additional properties that we can use. So I can look at age, I can choose to check if it has a value and that's going to be a Boolean property that indicates whether or not this nullable actually has an underlying value. If so, then I could copy this, for example. I could come down here and paste and now I could use age.value. And that is whatever that underlying type is. In this case, it's an Int. If I had a nullable of a date time, value would be of the type date time. And so before I access the value property, I want to check the HasValue property. If HasValue is false, and I try to access value, I'm going to get an exception. HasValue is true, I know that I'm free to access the value property to get the underlying value. What's happening on line 15 is that the nullable type actually defines explicit and implicit conversion operators so that it can convert from a nullable of Int for…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
(Locked)
Defining enums4m 39s
-
(Locked)
Enabling multiple enum values4m 3s
-
(Locked)
Testing enum values4m 13s
-
(Locked)
Understanding nullable types3m 24s
-
(Locked)
Using nullable types2m 14s
-
(Locked)
Working with null objects3m 25s
-
(Locked)
Understanding nullable reference types4m 23s
-
(Locked)
Working with nullable reference types4m 8s
-
(Locked)
Solution: Enum Flags1m 42s
-
(Locked)
-
-