C# StringCollection CopyTo

Description

StringCollection CopyTo copies the entire StringCollection values to a one-dimensional array of strings, starting at the specified index of the target array.

Syntax

StringCollection.CopyTo has the following syntax.


public void CopyTo(
  string[] array,
  int index
)

Parameters

StringCollection.CopyTo has the following parameters.

  • array - The one-dimensional array of strings that is the destination of the elements copied from StringCollection. The Array must have zero-based indexing.
  • index - The zero-based index in array at which copying begins.

Returns

StringCollection.CopyTo method returns

Example


using System;//from w ww. ja v a2  s  . co m
using System.Collections;
using System.Collections.Specialized;

public class SamplesStringCollection  {

   public static void Main()  {
      StringCollection myCol = new StringCollection();
      String[] myArr = new String[] { "A", "B", "C" };
      myCol.AddRange( myArr );

      String[] myArr2 = new String[myCol.Count];
      myCol.CopyTo( myArr2, 0 );

      Console.WriteLine( "The new array contains:" );
      for ( int i = 0; i < myArr2.Length; i++ )  {
         Console.WriteLine( "   [{0}] {1}", i, myArr2[i] );
      }
      Console.WriteLine();

   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Collections.Specialized »




BitVector32
HybridDictionary
ListDictionary
OrderedDictionary
StringCollection
StringDictionary
StringEnumerator