In C#, the foreach loop iterates collection types such as Array, ArrayList, List, Hashtable, Dictionary, etc. It can be used with any type that implements the IEnumerable interface.
C# Code:
1 2 3 4 5 6 7 8 9 10 11 12 |
static void Main(string[] args) { string[] array = new string[] { "Java", "Python","C#","C++", "JavaScript","PHP" }; foreach (string item in array) { Console.WriteLine(item); } Console.ReadLine(); } |
Output