Posted By

sureshdasari on 10/08/18


Tagged

visual Studio c# dotent


Versions (?)

C# Foreach Loop Example


 / Published in: C#
 

URL: https://www.tutlane.com/tutorial/csharp/csharp-foreach-loop-with-examples

Foreach loop is used to loop through an each item in array or collection object to execute the block of statements repeatedly

  1. using System;
  2.  
  3.  
  4.  
  5. namespace Tutlane
  6.  
  7. {
  8.  
  9. class Program
  10.  
  11. {
  12.  
  13. static void Main(string[] args)
  14.  
  15. {
  16.  
  17. string[] names = new string[3] { "Suresh Dasari", "Rohini Alavala", "Trishika Dasari" };
  18.  
  19. foreach (string name in names)
  20.  
  21. {
  22.  
  23. Console.WriteLine(name);
  24.  
  25. }
  26.  
  27. Console.WriteLine("Press Enter Key to Exit..");
  28.  
  29. Console.ReadLine();
  30.  
  31. }
  32.  
  33. }
  34.  
  35. }

Report this snippet  

You need to login to post a comment.