Link to home
Create AccountLog in
Avatar of zhshqzyc
zhshqzyc

asked on

Break foreach loop

var strings = new string[] { .... };
                 foreach (string item1 in strings)
                {
                    // doing something
                            foreach (string item2 in strings)
                                 {
                                      if( item1==item2)
                                           // want to break foreach loop
                                 }
                }

Open in new window

3x
ASKER CERTIFIED SOLUTION
Avatar of p_davis
p_davis

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Try this

var strings = new string[] { .... };
foreach (string item1 in strings)
{
    // doing something
    foreach (string item2 in strings)
    {
         if( item1==item2)
         {
             // want to break foreach loop
             break;
         }
    }
} 

Open in new window