How to for each loop in C# Array

Arrays are using for store similar data types grouping as a single unit. We can access Array elements by its numeric index. The array indexes start at zero. The default value of numeric array elements are set to zero, and reference elements are set to null. Click the following link to learn more about C# Arrays.

C# Array

Array Declaration and initialization

Retrieve a single item from Array.

It is very convenient to retrieve the Array elements using foreach loop . The following C# program shows how to retrieve the elements in an Array using foreach loop.

using System;
using System.Collections;
using System.Windows.Forms;

namespace WindowsApplication1
    public partial class Form1 : Form
        public Form1()

        private void button1_Click(object sender, EventArgs e)
            string[] week = new string[7];
            week[0] = "Sunday";
            week[1] = "Monday";
            week[2] = "Tuesday";
            week[3] = "Wednsday";
            week[4] = "Thursday";
            week[5] = "friday";
            week[6] = "Saturday";

            foreach (string day in week)
} (C) 2021    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.
SiteMap  | Terms  | About