All Type Coding

Search Here

How to get 2 Arrays as Input and append in 3rd array in c#

using System;

class program
{

    static void Main()
    {

        int[] a1 = new int[5];

        int[] a2 = new int[5];

        int[] a3 = new int[a1.Length + a2.Length];

        Console.WriteLine("Enter Any 5 Elements for the First Array :");

        for (int i = 0; i < 5; i++)
        {

            a1[i] = int.Parse(Console.ReadLine());

        }

        Console.WriteLine("Enter Any 5 Elements for the Second Array :");

        for (int i = 0; i < 5; i++)
        {

            a2[i] = int.Parse(Console.ReadLine());

        }

        Buffer.BlockCopy(a1, 0, a3, 0, a1.Length * sizeof(int));

        Buffer.BlockCopy(a2, 0, a3, a1.Length * sizeof(int), a2.Length * sizeof(int));

        Console.WriteLine("After Appending First and Second Arrays in Third Array :");

        foreach (int value in a3)
        {

            Console.WriteLine(value);

        }

        Console.ReadLine();
    }
}


Output will be :
 

No comments :

Post a Comment