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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.