foreach statement in C#

 

For Example: Write a program to demonstrate the use of foreach statement.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace ConsoleApplication42

{

class Program

    {

        static void Main(string[] args)

        {

            int[] a ={11,21,31,41,51};  //here a is array name

            foreach( int x in a)

            {

                Console.WriteLine("Value is : " + x);

              }

            Console.ReadLine();

        }

    }

 

Output:

Comments

Popular posts from this blog

simple program C#

Regular Expression Validator Control in asp.net

two dimension array in C#