逻辑没有进入第二个ElseIf

时间:2017-03-08 23:34:07

标签: vb.net

我有这样的事情:

   If Not String.IsNullOrWhiteSpace(selectedBeginDate) AndAlso someMoreConditionsHere Then
       If somethingElse Then
            ' Do some work here
       End If
   ElseIf String.IsNullOrWhiteSpace(selectedBeginDate) Then
       cell.IsEnabled = False
   ElseIf Not String.IsNullOrWhiteSpace(selectedBeginDate) Then
       cell.IsEnabled = True
   End If

在调试If somethingElse Then不正确时,它会正确进入

ElseIf String.IsNullOrWhiteSpace(selectedBeginDate) Then

正确地没有进入它,因为selectedBeginDate确实有值,但我希望它会转到下一个 ElseIf,但它跳过了它! !!!

为什么吗

1 个答案:

答案 0 :(得分:1)

另一种解决方案:

   If Not String.IsNullOrWhiteSpace(selectedBeginDate) AndAlso someMoreConditionsHere Then
       If somethingElse Then
            ' Do some work here
       End If
   Else
       cell.IsEnabled = Not String.IsNullOrWhiteSpace(selectedBeginDate) Then
   End If