首页 > 解决方案 > 休息时不会停止

问题描述

我正在使用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;

标签: c#while-loop

解决方案


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

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

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

等于

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

推荐阅读