C# NullReferenceException Demystified
What you'll learn
- Learn when NullReferenceException is thrown
- Use C# Nullable Operators to simplify null checks
- Identify troublesome code blocks by using Nullable References
- Use the Option type to avoid NullReferenceException
- Avoid NullReferenceException when working with LINQ FirstOrDefault method
Requirements
- Know the C# syntax to declare and initialize objects
- Write conditionals (such as if, else, and switch) and loops (such as for, while, and foreach)
- Work with collections like arrays and lists
- Have the latest version of the .NET SDK installed
Description
"Object reference not set to an instance of an object."
If you have found that scary exception message, you're not alone.
As C# software developers, we all have found it at some point.
I've found it dozens of times while working with past employers and clients on codebases of different sizes and complexities.
And often when we find it, the only thing we could do is fire up the Visual Studio debugger, go through the code line by line, and inspect all parameters and variables until finding the "object reference not set..." Boring and time-consuming. Arrrggg!
That's NullReferenceException in C#.
The "Billion-dollar mistake."
If you want to get rid of this exception from your code, this is the course for you.
Learn principles, features, and strategies to say goodbye to NullReferenceException—in 1 hour and 5 minutes, to be precise.
After finishing this course, you will:
Understand when NullReferenceException is thrown.
Use Nullable Operators to simplify null checks.
Work with Nullable References to identify troublesome code blocks.
Adopt the Option type as an alternative to Nullable References.
Safely use LINQ FirstOrDefault method.
No expertise required to write code free from the NullReferenceException.
You only need to be comfortable declaring and initializing objects and working with conditionals, loops, and collections such as arrays and lists.
See you in the first lesson and let's get rid of this exception once and for all.
Who this course is for:
- C# developers who want to write code free from the NullReferenceException
- C# developers who want to spend less time debuging their code to fix the NullReferenceException
Instructor
TL;DR: Software engineer, lifelong learner, language enthusiast, and avid reader.
Hello, there! I’m a software engineer working remotely based in Colombia (not Columbia) with more than 10 years of experience. I work as a C# backend engineer and content writer. I specialize in building APIs and backend code with .NET technologies — Mostly, ASP.NET Core and SQL Server these days.
I help teams grow high-quality backend software. And by high-quality, I mean maintainable and performant.
I write content, courses, and training for .NET teams. I like to work by combining my writing, teaching, and programming skills.
In my free time, I like to read books (on paper) and learn and teach foreign languages. (Currently, I'm learning Brazilian Portuguese: Oi, gente! Tudo bem?)