Foreach Loop statement Example in

It is one of the loop statement in the C# language. It is very easy to understand. In for or while loop we are using integer index, but in foreach loop we are using collection and returns each element in order. This is also called as enumeration.

Please check below example: Here we took animal array and writing each element using foreach loop.

    protected void Page_Load(object sender, EventArgs e)
        string[] animals = { "elephent", "lion", "zebra", "tiger" };
        foreach (string value in animals)
Share this post :

Post a Comment

Please give your valuable feedback on this post. You can submit any ASP.NET article here. We will post that article in this website by your name.

Support : Ranga Rajesh Kumar
Copyright © 2012. ASP.NET Examples - All Rights Reserved
Site Designed by Ranga Rajesh Kumar