Friday, 1 December 2017

C# Program to Get 2 Arrays as Input and Produce a 3rd Array by Appending one to other


Code:

using System;

class Program
{
    static void Main()
    {
        int[] array1 = new int[5];
        int[] array2 = new int[5];
        int[] array3 = new int[array1.Length + array2.Length];
        Console.WriteLine("Enter Any 5 Elements for the First Array :");
        for (int i = 0; i < 5; i++)
        {
            array1[i] = int.Parse(Console.ReadLine());
        }
        Console.WriteLine("Enter Any 5 Elements for the Second Array :");
        for (int i = 0; i < 5; i++)
        {
            array2[i] = int.Parse(Console.ReadLine());
        }
        Buffer.BlockCopy(array1,0,array3,0,array1.Length * sizeof(int));
        Buffer.BlockCopy(array2,0,array3,array1.Length * sizeof(int),array2.Length * sizeof(int));
        Console.WriteLine("Elements in the Third Array After Appending First and Second Arrays :");
        foreach (int value in array3)
        {
            Console.WriteLine(value);
        }
        Console.ReadLine();
    }
}


Output:

Enter Any 5 Elements for the First Array :
1
2
3
4
5
Enter Any 5 Elements for the Second Array :
6
7
8
9
10
Elements in the Third Array After Appending First and Second Arrays :
1
2
3
4
5
6
7
8
9
10



More C# Programs:


















100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...