C# What is nullable and what is not nullable?

GM Fuster
Mar 9, 2024

Very short summary on some of the nullability in C#.

I like to use | C# Online Compiler | .NET Fiddle (dotnetfiddle.net) because it lets you choose the .Net version.

Let’s see some examples.

Starting with value types.

Add the ? to make the value types nullable and now we can null them all.

Now for reference types.

Now we add #nullable enable (it can also be added to the project with <Nullable>enable</Nullable> (.NET 8)

Add ? like in the value types and now we don’t get that warning anymore:

Of course if you want to use it, instantiate the class.

See the little things to remember article for more regarding nulls.

--

--