Array:
An array stores a collection of elements of the same type. An array is used to store a collection of data and it size is fixed-size.
PROGRAM: (ArrayEg.cs)
using System;
class ArrayEg
{
public static void Main()
{
int []array1={12,23,34,45,56,67}; //without using new keyword
int []array2=new []{11,22,33,44}; //without using datatype
int []array3=new int[]{0,1,2,3}; //using new and datatype
int[] array4=new int[5]; //get elemets in runtime
Console.WriteLine("\n\n Array element in Array1");
foreach (int i in array1)
Console.WriteLine(i);
Console.WriteLine("\n\n Array element in Array2");
foreach (int i in array2)
Console.WriteLine(i);
Console.WriteLine("\n\n Array element in Array3");
foreach (int i in array3)
Console.WriteLine(i);
Console.WriteLine("Enter the array elements");
for (int j=0;j<5;j++)
{
array4[j]=int.Parse(Console.ReadLine()); //getting by user
}
Console.WriteLine("\n\n Array element in Array4");
foreach (int i in array4)
Console.WriteLine("Array elements:\t"+i);
}
}
OUTPUT:
D:\csharp>ArrayEg
Array element in Array1
12
23
34
45
56
67
Array element in Array2
11
22
33
44
Array element in Array3
0
1
2
3
Enter the array elements
4
3
2
1
0
Array element in Array4
Array elements: 4
Array elements: 3
Array elements: 2
Array elements: 1
Array elements: 0
PROGRAM EXPLANATION:
The above program explian about the array declaration,initialization and input to the array in run-time.
An array stores a collection of elements of the same type. An array is used to store a collection of data and it size is fixed-size.
PROGRAM: (ArrayEg.cs)
using System;
class ArrayEg
{
public static void Main()
{
int []array1={12,23,34,45,56,67}; //without using new keyword
int []array2=new []{11,22,33,44}; //without using datatype
int []array3=new int[]{0,1,2,3}; //using new and datatype
int[] array4=new int[5]; //get elemets in runtime
Console.WriteLine("\n\n Array element in Array1");
foreach (int i in array1)
Console.WriteLine(i);
Console.WriteLine("\n\n Array element in Array2");
foreach (int i in array2)
Console.WriteLine(i);
Console.WriteLine("\n\n Array element in Array3");
foreach (int i in array3)
Console.WriteLine(i);
Console.WriteLine("Enter the array elements");
for (int j=0;j<5;j++)
{
array4[j]=int.Parse(Console.ReadLine()); //getting by user
}
Console.WriteLine("\n\n Array element in Array4");
foreach (int i in array4)
Console.WriteLine("Array elements:\t"+i);
}
}
OUTPUT:
D:\csharp>ArrayEg
Array element in Array1
12
23
34
45
56
67
Array element in Array2
11
22
33
44
Array element in Array3
0
1
2
3
Enter the array elements
4
3
2
1
0
Array element in Array4
Array elements: 4
Array elements: 3
Array elements: 2
Array elements: 1
Array elements: 0
PROGRAM EXPLANATION:
The above program explian about the array declaration,initialization and input to the array in run-time.
good job .....try your ...endless
ReplyDelete