Copy List and array, starting at the specified index of the target array in CSharp

Description

The following code shows how to copy List and array, starting at the specified index of the target array.

Example


/*from   w w w.  j a  v  a2s  .c o m*/
using System;
using System.Collections;
using System.Collections.Generic;

class Sample
{
    public static void Main()
    {
        List<string> words = new List<string>();  

        words.Add("A");
        words.Add("B");
        words.Add("C");
        words.Add("D");
        words.Add("E");
        words.Add("F");

        string[] existing = new string[10];
        words.CopyTo(existing,2);
        
        foreach(String s in existing){
           Console.WriteLine(s);
        }
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Collections »




ArrayList
BitArray
Collection
Comparer
HashSet
Hashtable
LinkedList
List
ListDictionary
OrderedDictionary
Queue
SortedList
SortedSet
Stack
StringCollection
StringDictionary