943,699 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 600
  • C# RSS
May 18th, 2009
0

Foreach Loop

Expand Post »
How to break or get out of foreach loop while searching folder for files or something like that
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
gallian99 is offline Offline
77 posts
since Jan 2009
May 18th, 2009
0

Re: Foreach Loop

Simple

C# Syntax (Toggle Plain Text)
  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.
Reputation Points: 2023
Solved Threads: 644
Senior Poster
ddanbe is offline Offline
3,736 posts
since Oct 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Mean & Standar deviation in C#
Next Thread in C# Forum Timeline: notepad c#





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC