StringDictionary.CopyTo(Array, Int32) 메서드

정의

문자열 사전 값을 지정된 인덱스의 1차원 Array 인스턴스에 복사합니다.

public:
 virtual void CopyTo(Array ^ array, int index);
public virtual void CopyTo(Array array, int index);
abstract member CopyTo : Array * int -> unit
override this.CopyTo : Array * int -> unit
Public Overridable Sub CopyTo (array As Array, index As Integer)

매개 변수

array
Array

에서 복사StringDictionary한 값의 대상인 1차원 Array 입니다.

index
Int32

복사가 시작되는 배열의 인덱스입니다.

예외

array 가 다차원입니다.

-또는-

의 요소 StringDictionary 수가 사용 가능한 공간 indexarray보다 큰 경우

arraynull입니다.

index 가 .의 array하한보다 작습니다.

예제

다음 코드 예제에서는 StringDictionary를 배열에 복사하는 방법을 보여 줍니다.

using System;
using System.Collections;
using System.Collections.Specialized;

public class SamplesStringDictionary  {

   public static void Main()  {

      // Creates and initializes a new StringDictionary.
      StringDictionary myCol = new StringDictionary();
      myCol.Add( "red", "rojo" );
      myCol.Add( "green", "verde" );
      myCol.Add( "blue", "azul" );

      // Displays the values in the StringDictionary.
      Console.WriteLine( "KEYS\tVALUES in the StringDictionary" );
      foreach ( DictionaryEntry myDE in myCol )
         Console.WriteLine( "{0}\t{1}", myDE.Key, myDE.Value );
      Console.WriteLine();

      // Creates an array with DictionaryEntry elements.
      DictionaryEntry[] myArr = { new DictionaryEntry(), new DictionaryEntry(), new DictionaryEntry() };

      // Copies the StringDictionary to the array.
      myCol.CopyTo( myArr, 0 );

      // Displays the values in the array.
      Console.WriteLine( "KEYS\tVALUES in the array" );
      for ( int i = 0; i < myArr.Length; i++ )
         Console.WriteLine( "{0}\t{1}", myArr[i].Key, myArr[i].Value );
      Console.WriteLine();
   }
}

/*
This code produces the following output.

KEYS    VALUES in the StringDictionary
green   verde
red     rojo
blue    azul

KEYS    VALUES in the array
green   verde
red     rojo
blue    azul

*/
Imports System.Collections
Imports System.Collections.Specialized

Public Class SamplesStringDictionary

   Public Shared Sub Main()

      ' Creates and initializes a new StringDictionary.
      Dim myCol As New StringDictionary()
      myCol.Add("red", "rojo")
      myCol.Add("green", "verde")
      myCol.Add("blue", "azul")

      ' Displays the values in the StringDictionary.
      Console.WriteLine("KEYS" + ControlChars.Tab + "VALUES in the StringDictionary")
      Dim myDE As DictionaryEntry
      For Each myDE In  myCol
         Console.WriteLine("{0}" + ControlChars.Tab + "{1}", myDE.Key, myDE.Value)
      Next myDE
      Console.WriteLine()

      ' Creates an array with DictionaryEntry elements.
      Dim myArr As DictionaryEntry() =  {New DictionaryEntry(), New DictionaryEntry(), New DictionaryEntry()}

      ' Copies the StringDictionary to the array.
      myCol.CopyTo(myArr, 0)

      ' Displays the values in the array.
      Console.WriteLine("KEYS" + ControlChars.Tab + "VALUES in the array")
      Dim i As Integer
      For i = 0 To myArr.Length - 1
         Console.WriteLine("{0}" + ControlChars.Tab + "{1}", myArr(i).Key, myArr(i).Value)
      Next i
      Console.WriteLine()

   End Sub

End Class


'This code produces the following output.
'
'KEYS    VALUES in the StringDictionary
'green   verde
'red     rojo
'blue    azul
'
'KEYS    VALUES in the array
'green   verde
'red     rojo
'blue    azul

설명

CopyTo 는 typecast할 수 있는 개체를 복사합니다 System.Collections.DictionaryEntry. DictionaryEntry 에는 키와 값이 모두 포함됩니다.

복사된 Array 요소는 열거자가 반복하는 순서와 동일한 순서로 정렬됩니다 StringDictionary.

이 메서드는 O(n) 연산입니다. 여기서 nCount.

적용 대상