休息不会停止

时间:2018-08-16 13:21:53

标签: c# while-loop

我正在使用while并在其中进行检查,我在else中放置了一个断点,看起来一切正常,代码执行了验证并转至BREAK,但是循环没有停止...

Cliente cliente = null;

do {
  cliente = DataBase.Clientes.FirstOrDefault(x => x.Status == 0);

  if (cliente.NossoNumero == string.Empty || cliente.Email == string.Empty) {
    cliente.UpdateStatus(Status.Error);
  } 
  else {
    break;
  }
}
while (DataBase.Clientes.FirstOrDefault(x => x.Status == 0) != null);

return cliente;

1 个答案:

答案 0 :(得分:-1)

如果您有多个clinet? 为什么不返回IEnumrable列表,然后更新每个客户端?

循环也不会停止,因为它说:

while (DataBase.Clientes.FirstOrDefault(x => x.Status == 0) != null);

等于

while (I have at least one client with status == 0)