Arrays in C#
public static void Main()
{
int[] arr = {5, 1, 10, 33, 100, 4};
Array.Sort(arr);
foreach (int v in arr)
Console.WriteLine("Element: {0}", v);
//Making random array
DateTime now = DateTime.Now;
Random rand = new Random ((int) now.Millisecond);
int [] Arr = new int [12];
for (int x = 0; x < Arr.Length; ++x)
{
Arr [x] = rand.Next () % 101;
}
//initialising 2 D array
int[,] sqrs = {
{ 1, 1 },
{ 2, 4 },
{ 3, 9 },
{ 4, 16 },
{ 5, 25 },
{ 6, 36 },
{ 7, 49 },
{ 8, 64 },
{ 9, 81 },
{ 10, 100 }
};
//jagged array
int[][] jagged = new int[3][];
jagged[0] = new int[4];
jagged[1] = new int[3];
jagged[2] = new int[5];
int i;
// store values in first array
for(i=0; i < 4; i++)
jagged[0][i] = i;
}
No comments:
Post a Comment