Inserting and displaying elements in an array, using methods. The size is given by user and an array with that size is created and displayed.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
arraysizeexample axe = new arraysizeexample();
int[] localarray = axe.arrayexample(10);
axe.showarray(localarray);
Console.ReadLine();
}
}
class arraysizeexample
{
public int[]
arrayexample(int size)
{
int[] a = new int[size];
{
a[i] = i +1;
}
return a;
}
public void
showarray(int[] intarry)
{
for (int i = 0;
i < intarry.Length; i++)
{
Console.WriteLine("The {0} element of array is : {1}", i,
intarry[i]);
}
}
}
}
No comments:
Post a Comment