In .NET Core 2.1 (or any previous version of .NET), we could legitimately type the following code and run it:
string test = null; Console.WriteLine(test.Length);
And, of course it would crash. Obviously, no-one familiar with the language would write this; however, they might write something as follows:
string test = FunctionCanReturnNull(); Console.WriteLine(test.Length);
Nullable reference types are an opt-in feature (that is, you have to explicitly turn it on) that simply gives a warning to say that you have a potential for a reference type to be null. Let's try turning this on for our Ebook Manager. It can be turned on a class-by-class basis by adding the following directive to the top of a file: ...