Foreach Loop

Please support our C# advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jan 2009
Posts: 68
Reputation: gallian99 is an unknown quantity at this point 
Solved Threads: 0
gallian99 gallian99 is offline Offline
Junior Poster in Training

Foreach Loop

 
0
  #1
May 18th, 2009
How to break or get out of foreach loop while searching folder for files or something like that
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,056
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 313
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Postaholic

Re: Foreach Loop

 
0
  #2
May 18th, 2009
Simple

  1. namespace ConsoleApplication1
  2. {
  3. class Program
  4. {
  5. static void Main(string[] args)
  6. {
  7. int[] MyNums = { 1, 2, 3, 4, 5 };
  8. foreach (int i in MyNums)
  9. {
  10. if (i == 3) break;
  11. Console.WriteLine(i);
  12. }
  13. Console.ReadKey();
  14. }
  15. }
  16. }

This should only print 1 and 2 to the console.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 375 | Replies: 1
Thread Tools Search this Thread



Tag cloud for C#
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC