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.
Working with nullable reference types - C# Tutorial
From the course: C# Essential Training 1: Types and Control Flow
Working with nullable reference types
- [Instructor] As we work with these nullable reference types, let's start here at the top of the file and work our way down applying the different features that comprise that nullable reference type. So I'm getting a warning here because, string in this context now that I've made that project level change, isn't nullable. It's like an int or a date time of value type, but it still behaves as a reference type. I can use that same syntax, putting a question mark at the end just like I did for the value types, to indicate that this is a nullable reference type. So again, it's all about providing that compiler help. We see that now it's okay to assign null there. If we go down to the next place for our string that we're having a problem is line 16 where that input could be null. One of the things we can do is go to our method now and apply an attribute that says allow null, that's not in scope in the namespace here but if I hit control + period there, using system diagnostics code…
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)
-
-