Working with Nulls in C# 9
Unexpected null values and NullReferenceExceptions can be a constant source of bugs resulting in wasted development time and out-of-hours support callouts. This course will teach you how to reduce null related errors in your code.
What you'll learn
Making use of an object when it is not supposed to be null can result in unexpected exceptions that can cause your program to crash. These unexpected null related errors may cause data loss or corruption, system downtime, and unhappy users. In this course, Working with Nulls in C# 9, you’ll gain the ability to reduce the likelihood of getting null related exceptions in production. First, you’ll explore which objects can be set to null and how to check for null values. Next, you’ll discover a design pattern to help eliminate null related exceptions. Finally, you’ll learn how to opt-in to the ability to create non-nullable reference types that enable the compiler to detect null-related problems before you even run your application. When you’re finished with this course, you’ll have the skills and knowledge of nulls in C# needed to reduce null related errors in your production code.
Table of contents
- Version Check 0m
- Introduction 2m
- Reference and Value Types Overview 2m
- What Is a NullReferenceException? 2m
- Using Magic Numbers for Null Value Types 5m
- Introduction to Nullable Value Types with Nullable<T> 2m
- Refactoring to Nullable<T> and Removing Magic Numbers 2m
- C# Shorthand for Nullable Value Types 1m
- Nullable Boolean Values 2m
- Understanding Null and Empty Strings 1m
- Checking for Null or Empty Strings 2m
- Summary 2m
- Introduction 1m
- More on Nullable<T> 2m
- Using the HasValue and Value Properties 3m
- Using the GetValueOrDefault Method 2m
- Comparing Nullable<T> Instances 1m
- Nullable<T> Conversions and Default Values 3m
- Overview of C# Null-related Operators 1m
- Using the Conditional Operator to Check for Nulls 2m
- Using the Null-coalescing Operator 1m
- The Null-coalescing Assignment Operator 2m
- Using the Null-conditional Operator 6m
- Using the Null-conditional Operator with Null Array Values 3m
- Thread-safe Null Delegate Invocation 1m
- Summary 2m
- Introduction 2m
- Overview of Null Features 3m
- Writing Some Simple Null Code 2m
- Enabling Non-nullable Reference Types for Specific Lines of Code 2m
- Enabling Non-nullable Reference Types for an Entire Code File 2m
- Enabling Non-nullable Reference Types for an Entire Project 1m
- Treating Nullable Warnings as Errors 2m
- Specifying That a Reference Is Allowed to Be Null 1m
- Working with Nullable and Non-nullable Properties 5m
- Working with Nullable and Non-nullable Method Return Values 1m
- Using the Null-coalescing and Null-conditional Operators 2m
- Using the Null-forgiving Operator to Override the Compiler 5m
- Refactoring Existing Code to Use Non-nullable Reference Types 8m
- Nullable and Non-nullable Generics 4m
- Considerations and Limitations 3m
- Summary 2m
- Introduction 1m
- An Overview of Null-related Attributes 1m
- Precondition Attributes Overview 1m
- Using the AllowNull Attribute 3m
- Using the DisallowNull Attribute 2m
- Postcondition Attributes Overview 1m
- Using the NotNull Attribute 2m
- Using the MaybeNull Attribute 4m
- Conditional Postcondition Attributes Overview 1m
- Using the NotNullWhen Attribute 3m
- Using the MaybeNullWhen Attribute 2m
- Using NotNullIfNotNull Attribute 2m
- Constructor Helper Method Attributes Overview 2m
- Unreachable Code Attributes Overview 1m
- Using the DoesNotReturn Attribute 3m
- Considerations 3m
- Summary, Resources, and Further Learning 3m