Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,945 questions

51,887 answers

573 users

How to copy array section to another in C#

2 Answers

0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] arr = new int[6];

            arr[0] = 1;
            arr[1] = 2;
            arr[2] = 3;
            arr[3] = 4;
            arr[4] = 5;
            arr[5] = 6;

            int[] arr_copy = new int[4];

            Array.Copy(arr, 0, arr_copy, 0, 4);

            for (int i = 0; i < arr_copy.Length; i++)
                Console.WriteLine(arr_copy[i]);
        }
    }
}

/*
run:

1
2
3
4

*/

 



answered Jan 6, 2017 by avibootz
0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            char[] arr = new char[6];

            arr[0] = 'a';
            arr[1] = 'b';
            arr[2] = 'c';
            arr[3] = 'd';
            arr[4] = 'e';
            arr[5] = 'f';

            char[] arr_copy = new char[6];

            Array.Copy(arr, 1, arr_copy, 0, 3);

            for (int i = 0; i < arr_copy.Length; i++)
                Console.WriteLine(arr_copy[i]);
        }
    }
}

/*
run:

b
c
d

*/

 



answered Jan 6, 2017 by avibootz

Related questions

...