Udemy
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
Turn what you know into an opportunity and reach millions around the world.
Learn More
Your cart is empty.
Keep shopping
C# NullReferenceException Demystified
5 students

C# NullReferenceException Demystified

Learn principles, features, and strategies to avoid NullReferenceException in less than 1 hour
Created byCesar Aguirre
Last updated 2/2025
English

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

Course content

3 sections • 17 lectures • 1h 5m total length
  • Introduction1:21

    Welcome! Let's learn principles, features, and techniques to get rid of NullReferenceException. Fire up your Visual Studio or favorite IDE, download the companion source code, and let's get rid of this exception once and for all.

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:

  1. Understand when NullReferenceException is thrown.

  2. Use Nullable Operators to simplify null checks.

  3. Work with Nullable References to identify troublesome code blocks.

  4. Adopt the Option type as an alternative to Nullable References.

  5. 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