Main() : void
{
def p : int? = 20;
when (p != 20 :> int?)
Console.WriteLine("A");
when (p == 20 :> int?)
Console.WriteLine("B");
when (!(p == 20 :> int?))
Console.WriteLine("C");
}
Вот код который получается при просмотре рефлектором
Debug:
private static void Main()
{
int? p = 20;
if (p == 20)
{
Console.WriteLine("A");
}
if (p == 20)
{
Console.WriteLine("B");
}
if (p != 20)
{
Console.WriteLine("C");
}
}
Release:
private static void Main()
{
int? p = 20;
int? nullable = 20;
if ((p.GetValueOrDefault() == nullable.GetValueOrDefault()) && (p.HasValue == nullable.HasValue))
{
Console.WriteLine("A");
}
nullable = 20;
if ((p.GetValueOrDefault() == nullable.GetValueOrDefault()) && (p.HasValue == nullable.HasValue))
{
Console.WriteLine("B");
}
nullable = 20;
if ((p.GetValueOrDefault() != nullable.GetValueOrDefault()) || (p.HasValue != nullable.HasValue))
{
Console.WriteLine("C");
}
}
Несмотря на то, что указанно
!= значения сравниваются.