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

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…

Contents