Looping over a string array


/ Published in: C#
Save to your folder(s)

Simple example of looping over a string array.


Copy this code and paste it in your HTML
  1. using System;
  2.  
  3. class Program
  4. {
  5. static void Main()
  6. {
  7. string[] arr = new string[4]; // Initialize
  8. arr[0] = "one"; // Element 1
  9. arr[1] = "two"; // Element 2
  10. arr[2] = "three"; // Element 3
  11. arr[3] = "four"; // Element 4
  12.  
  13. // Loop over strings
  14. foreach (string s in arr)
  15. {
  16. Console.WriteLine(s);
  17. }
  18. }
  19. }

URL: http://www.dotnetperls.com/loop-string-array

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.