Сравнение с Nullable
От: _nn_ www.nemerleweb.com
Дата: 29.11.10 13:07
Оценка:
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");
    }
}


Несмотря на то, что указанно != значения сравниваются.
http://rsdn.nemerleweb.com
http://nemerleweb.com
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.