In .Net 2, the code:
namespace ns
{
class Class1
{
Nullable<int> a;
}
}
does not compile and gives the error:
The type or namespace name 'Nullable' could not be found (are you missing a using directive or an assembly reference?)
It is missing using System;
but this code:
namespace ns
{
class Class1
{
int? a;
}
}
compiles.
Can somebody explain why?
The T?
syntax is translated by the compiler into System.Nullable<T>
by referencing the type directly, rather than by examining the using
s that are in scope. You could similarly write this and the compiler would succeed:
System.Nullable<int> a;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With