Working with Nulls in C#
Learn how to create, check for, access, and eliminate nulls in your C# applications.
What you'll learn
Unexpected null values and NullReferenceExceptions can be a constant source of bugs resulting in wasted time and out of hours support callouts. In this course, Working with Nulls in C#, you're going to learn about the different ways that null values pop up in C# code and how to deal with them. First, you're going to learn the fundamentals of why you get null values and the difference between value and reference types. Next you'll learn how you can use the various C# operators to check for and manipulate nulls. Finally, you'll learn how to think about nulls at a higher abstraction level in your object-oriented code. By the end of this course, you'll understand the different types of objects in C#, how to correctly create nullable value types, how to use C# operators to work with nulls with fewer lines of code, and how to implement the Null Object pattern to remove the need to write repetitive null checking code.
Table of contents
- Introduction 1m
- Course Outline 1m
- Reference and Value Types Overview 4m
- Using Magic Numbers for Null Value Types 10m
- Introduction to Nullable Value Types with Nullable<T> 1m
- Refactoring to Nullable<T> and Removing Magic Numbers 3m
- C# Shorthand for Nullable Value Types 2m
- Nullable Boolean Values 3m
- Null and Empty Strings 2m
- Checking for Null or Empty Strings 2m
- Summary 2m
- Introduction 2m
- More on Nullable<T> 1m
- Using the HasValue and Value Properties 3m
- Using the GetValueOrDefault Method 2m
- Comparing Nullable<T> Instances 1m
- Nullable<T> Implicit and Explicit Conversions 2m
- Overview of C# Null-checking Operators 2m
- Using the Conditional Operator to Check for Nulls 2m
- Using the Null-coalescing Operator 2m
- Using the Null-conditional Operator 7m
- Using the Null-conditional Operator with Null Array Values 3m
- Thread-safe Null Delegate Invocation 1m
- Summary 2m