C# 这个If语句有什么问题

C# 这个If语句有什么问题,c#,if-statement,C#,If Statement,我有一个关于这个IF的陈述 else if (dtpFechaResol.Value.ToShortDateString().Equals(DateTime.Now.ToShortDateString())) { DialogResult dialogResult = MessageBox.Show("Are you sure", "Error!", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (dialog

我有一个关于这个IF的陈述

else if (dtpFechaResol.Value.ToShortDateString().Equals(DateTime.Now.ToShortDateString()))
{
    DialogResult dialogResult = MessageBox.Show("Are you sure", "Error!", MessageBoxButtons.YesNo, MessageBoxIcon.Information);

    if (dialogResult == DialogResult.No) dtpFechaResol.Focus();
}
// This Statement is Jumping  
else if (blNuevo && cbCaja.SelectedIndex >= 0 && txtResolucion.Text.Trim().Length > 0)
{
    ........
}
如果第一个else if不满足条件,则验证第二个else if,但如果第一个else if满足条件,则第二个else if跳转

我的理解是,在第一条语句中,当验证dialogResult时,答案是“是”,下一条语句必须验证,但不验证

其他的如果是五,但是这两个让我成了问题

有人可以告诉我我的问题是什么

这就是else if构造的工作原理。执行计算结果为true的第一个else if,而忽略整个if…else if块中的后续else if部分


如果您想保证对多个条件进行评估,请将它们分成单独的If块。

@Karls答案正确。要可视化执行if-else-if块的方式,只需添加一些缩进:

if (conditionA)
{
    statementA
}
else if (conditionB)
     {
        statementB
     }
     else if (conditionC)
          {
              statementC
          }
我不喜欢这种有条件的区块安排。因为实际上在方法中有很深的嵌套条件,这些条件被不良的缩进隐藏