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
Post a Comment