C# – Arrays Example

 In C# programming language an array is a fixed sequenced collection of elements of the same data type. It is simply a grouping of like type data. In the simplest form, an array can be used to represent a list of numbers, or a list of names

Declaring an array does not initialize the array in the memory. When the array variable is initialized, you can assign values to the array.

Array is a reference type, so you need to use the new keyword to create an instance of the array. For example,

int[] balance = new int[10];

You can also create and initialize an array, as shown

int [] num = new int[5]  { 12,  14, 75, 47, 85};

You can copy an array variable into another target array variable. In such case, both the target and source point to the same memory location :

int [] num = new int[]  { 12, 14, 75, 47, 85};
int[] NewNum= num ;

Now See Array Example in C# :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace _1D_Array
{
class Program
{
static void Main(string[] args)
{
int[] a = new int[5];
int i;
for (i = 0; i <= 4; i++)
{
Console.WriteLine(“enter the value“);
a[i] = Convert.ToInt32(Console.ReadLine());

}
for (i = 0; i <= 4; i++)
{
Console.WriteLine(a[i]);
}
}
}
}

OUTPUT : TO See output to run the Consol Application

2 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *