Join Reynald Adolphe for an in-depth discussion in this video Using null-conditional operators, part of C# 6.0 First Look.
- Sometimes checking for null can become tedious,…but now we have null-conditional operators,…which allows you to reach members and elements…only when the receiver is not null.…Let's show a typical example of checking for null…before C# 6.…If I wanted to get the numberOfartists,…all I need to do is say artists equals,…if artists = null, then return null.…
Of course, I have to cast that into a null integer.…If not, then return me the count.…That's how we would do it on a version before C# 6.…However, now what we can do is simply state…if the artists is not null, and we do this by…adding the question mark, if it is not null,…return me to count.…
If artists was null, it would short circuit…and not go any further.…This would remain null.…Let's go ahead and write this to our console.…And we get the number two, since there were…two in our collection.…The other thing I'd like to show you is that…likewise, we could also use this when…getting the first element at an index,…particularly, like let's say, index of zero.…
So, if I wanted to get the first artist in our collection,…
- Introducing the new IDE in Visual Studio 2015
- Leveraging nameof expressions
- Using index initializers
- Using await in catch and finally blocks
- Using static
- Resolving conflict instance methods
Skill Level Beginner
1. Touring the Enhanced IDE
2. Expression-Level Features
3. Statement-Level Features
Adding exception filters2m 42s
4. Member Declaration and Initialization Features
5. Improved Debugging
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.