c# .net Adsense ADO.NET Linq Viruses/security asp.net MVC JQuery Angular-js Node-js SEO Java C++ SQL API Networking vb.net .Net Css JavaScript Generics c#.Net entity framework HTML Website host Website Construction Guide HTTP tutorial W3C tutorial Web Services JSON Psychology Ionic framework Angular ReactJS Python Computer Android
c# .net

how to use foreach loop over arrays in C#?

| | CSharp

Foreach Loop In C# is used to access or iterate each item in a collection. We use foreach, on a string array, to loop through the elements in the array.


 


class exampleforeach
{
static void Main()
{
string[] animals = { "monkey", "elephant", "lion" };
// ... Loop with the foreach keyword.
foreach (string value in animals )
{
Console.WriteLine(value);
}
}
}


Output:
monkey
elephant
lion