How do I exit a foreach loop in C#?

后端 未结 5 1868
温柔的废话
温柔的废话 2020-12-09 14:36
foreach (var name in parent.names)
{
    if name.lastname == null)
    {
        Violated = true;
        this.message = \"lastname reqd\";
    }

    if (!Violated)         


        
5条回答
  •  长情又很酷
    2020-12-09 14:54

    During testing I found that foreach loop after break go to the loop beging and not out of the loop. So I changed foreach into for and break in this case work correctly- after break program flow goes out of the loop.

提交回复
热议问题