Deep Dive With Nullable Value Types in C#

 Recently nullable reference types have become trendy. Meanwhile, the good old nullable value types are still here and actively used. How well do you remember the nuances of working with them? Let’s recall your memory or test your knowledge by reading this article. Examples of C# and IL code, references to the CLI specification code is provided. Let’s start with an interesting case. Let’s Deep dive with Nullable value types in C#.

Take a look at the below sample code and try to answer what will be output to the console. And, just as importantly, why it would be. Just let’s agree right away that you will answer as it is: without compiler hints, documentation, reading literature, or anything like that.

static void NullableTest()
{
  int? a = null;
  object aObj = a;
 
  int? b = new int?();
  object bObj = b;
 
  Console.WriteLine(Object.ReferenceEquals(aObj, bObj)); // True or False?
}


Post a Comment

0 Comments