0

How to break or get out of foreach loop while searching folder for files or something like that

2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by ddanbe
0

Simple

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] MyNums = { 1, 2, 3, 4, 5 };
            foreach (int i in MyNums)
            {
                if (i == 3) break;
                Console.WriteLine(i);
            }
            Console.ReadKey();
        }
    }
}

This should only print 1 and 2 to the console.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.