What is Array?

1/8/2020 12:47:17 AM

An array stores a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type stored at contiguous memory locations. In this C# must Define the array type. Like int,string,float etc

Note:  Array Start in 0 index.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Reflection;
using testForClass1;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace testFor
    public class Program
        static void Main(string[] args)
            //Define the array name is myArray and length is 9 also type int
            int[] myArray = new int[9];
            //Assin the array, array name is Array and length is 5 also type int
            int[] Array = new int[5] { 10, 20, 30, 40, 50 };
            //Assin the array, array name is ArrayFloat and length is 5 also type float
            float[] ArrayFloat = new float[5] { 10.3f, 20.1f, 30.3f, 40.8f, 50.0f };
            string[] studentName = new string[3] { "Jesy", "Reza", "Tofile" };
            //print the studentName arry using for loop
            for (int i = 0; i < studentName.Length; i++)
                Console.WriteLine("Student Name : "+ studentName[i]);

In this code ' i ' represent the index of this element. An array is used to store a collection of data, so if we print the collection, we must use the loop.