Copy the entire Collection to a compatible one-dimensional Array, starting at the specified index of the target array in CSharp

Description

The following code shows how to copy the entire Collection to a compatible one-dimensional Array, starting at the specified index of the target array.

Example


using System;/*w  ww  . j  a va 2  s  .  co m*/
using System.Collections.Generic;
using System.Collections.ObjectModel;

public class Demo
{
    public static void Main()
    {
        Collection<string> myData = new Collection<string>();

        myData.Add("A");
        myData.Add("B");
        myData.Add("C");
        myData.Add("D");
        
        string[] s = new string[10];
        
        myData.CopyTo(s,0);

        foreach( string item in s)
        {
            Console.WriteLine(item);
        }        
    }
}

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