I created a new C#10/.net6 library project in VS2022 using the standard template, NRTs are enabled by default (nullable : enabled). I notice that nullable reference types do not appear to support Nullable
properties Value
and HasValue
MRE (using #nullable annotation explicitly)
using System;
public class Program
{
public static void Main()
{
#nullable enable
object? o =null;
if(o.HasValue)
{}
Console.WriteLine("Hello World");
}
}
'object' does not contain a definition for 'HasValue' and no accessible extension method 'HasValue' accepting a first argument of type 'object' could be found
Are nullable reference types not actually Nullable<T>
? o
is declared as object?
so why does the compiler refer to object
rather than object?
?