What is a foreach loop in C#?
- A foreach loop is a different kind of looping constructs in C# programming that doesn’t include initialization, termination and increment/decrement things.
- It uses collection to take value one by one and then processes on them.
- It eliminates errors caused by incorrect index handling.
- At any point within the foreach block, you can break out of the loop by using the break keyword, or step to the next iteration in the loop by using the continue keyword.
- A foreach loop can also be exited by the goto, return, or throw statements.
Syntax of foreach loop
foreach (string name in array)
{
}
Example
class Program
{
static void Main(string[] args)
{
string[] array = new string[5]; // declaring array
//Storing value in array element
array[0] = "Ehtesham";
array[1] = "Raza";

Ehtesham MehmoodPosted Nov 23, 2014, 6:02 PM
sundar rajan Thank u :)
sundar rajanPosted Jul 7, 2014, 9:58 AM
This is so nice Thank you