Introduction

In this article I explain how to select a subarray from an array. However there are several ways to fetch a subarray from an array. Here I describe a very simple and easy way to select a subarray from an array using the built-in method to copy an array.

Use this simple procedure to get a subarray from an array.

Step 1

Open a console application and write the following simple code:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

int[] arr={12,45,78,36,97,85,45,68,25,30,78};

int[] arr2=new int[5];

Array .Copy (arr,2,arr2,0,5);

foreach (int a in arr2 )

{

Console .Write (a + " ");

}

Console.Read();

}

}

}

Step 2


Now run your application and see the output.


subarray.jpg