example of array using C#?

Sagarp
Posted by Sagarp under C# category on | Views : 2178
using System;

namespace day1
{
/// <summary>
/// Summary description for Class4.
/// </summary>
public class Class4
{
[STAThread]
static void Main(string[] args)
{
int [] arr=new int[3];
Console.WriteLine ("Enter the Element :");
for(int i=0;i<arr.Length ;i++)
{
arr[i]=Convert.ToInt32 (Console.ReadLine());
}
for(int i=0;i<arr.Length ;i++)
{
Console.WriteLine("arr[{0}]={1}",i,arr[i]);

}
Console.Read ();
}

}
}


----------------------------------------------------------------------------------------------------------------------------------
using System;

namespace day1
{
/// <summary>
/// Summary description for Class5.
/// </summary>
public class Class5
{
static void Main(string[] args)
{
int[,] arr1=new int[3,3];
Console.WriteLine("rows{0}=",arr1.GetLength(0));
Console.WriteLine("Columns{0}=",arr1.GetLength(1));
Console.WriteLine("Enter array elements");
int i,j;
for(i=0;i<arr1.GetLength(0);i++)
{
for(j=0;j<arr1.GetLength(1);j++)
{
Console.Write("arr[{0},{1}]=",i,j);
arr1[i,j]=Convert.ToInt32(Console.ReadLine());

}
}

Console.WriteLine("The Element are:");
for(i=0;i<arr1.GetLength(0) ;i++)
{
for(j=0;j<arr1.GetLength(1);j++)
{
Console.Write(arr1[i,j]);
Console.Write("");
}
Console.WriteLine();

}

Console.Read ();
}

Comments or Responses

Login to post response