Q:

C# | printing an integer array using foreach loop

0

Given an integer array and we have to print its elements using "foreach loop" in C#.

Syntax for foreach loop:

    foreach (element in iterable-item)
    {
        // body of foreach loop
    }

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] data = { 12, 45, 67, 879, 89 };
            foreach(int item in data)
            {
                Console.WriteLine(item);
            }
            Console.ReadKey();
        }
    }
}

Output

12
45
67
879
89

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now