StringDictionary.CopyTo メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > StringDictionary.CopyTo メソッドの意味・解説 

StringDictionary.CopyTo メソッド

1 次元Array インスタンス指定したインデックス位置に、文字列ディクショナリの値をコピーします

名前空間: System.Collections.Specialized
アセンブリ: System (system.dll 内)
構文構文

例外例外
例外種類条件

ArgumentException

array多次元です。

または

StringDictionary要素数が、index から array末尾までに格納できる数を超えてます。

ArgumentNullException

arraynull 参照 (Visual Basic では Nothing) です。

ArgumentOutOfRangeException

indexarray下限より小さい値です。

解説解説

CopyTo は、System.Collections.DictionaryEntry に型キャストできるオブジェクトコピーしますDictionaryEntry には、キーと値の両方格納されます。

Arrayコピーされる要素は、列挙子が StringDictionary反復処理するのと同じ順序並べ替えられます。

このメソッドは O(n) 操作です。ここで、nCount です。

使用例使用例

StringDictionary を配列コピーする方法については、次のコード例参照してください

Imports System
Imports System.Collections
Imports System.Collections.Specialized
Imports Microsoft.VisualBasic

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 'Main 

End Class 'SamplesStringDictionary


'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

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

*/
#using <System.dll>

using namespace System;
using namespace System::Collections;
using namespace System::Collections::Specialized;
void main()
{
   
   // Creates and initializes a new StringDictionary.
   StringDictionary^ myCol = gcnew 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"
 );
   IEnumerator^ myEnum = myCol->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      DictionaryEntry^ myDE = safe_cast<DictionaryEntry^>(myEnum->Current);
      Console::WriteLine( "{0}\t{1}", myDE->Key, myDE->Value );
      Console::WriteLine();
      
      // Creates an array with DictionaryEntry elements.
      array<DictionaryEntry>^myArr = gcnew array<DictionaryEntry>(3);
      
      // 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

*/
import System.* ;
import System.Collections.IEnumerator;
import System.Collections.DictionaryEntry;
import System.Collections.Specialized.* ;

public class SamplesStringDictionary
{   
    public static void main(String[]
 args)
    {                
        // 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");
        IEnumerator objEnum = myCol.GetEnumerator();
        while (objEnum.MoveNext()) { 
            DictionaryEntry myDE = (DictionaryEntry)objEnum.get_Current();
            Console.WriteLine("{0}\t{1}", myDE.get_Key(), myDE.get_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].get_Key(),
                myArr[i].get_Value());
        } 
        Console.WriteLine();
    } //main 
} //SamplesStringDictionary

/*
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

*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
StringDictionary クラス
StringDictionary メンバ
System.Collections.Specialized 名前空間


このページでは「.NET Framework クラス ライブラリ リファレンス」からStringDictionary.CopyTo メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からStringDictionary.CopyTo メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からStringDictionary.CopyTo メソッド を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

StringDictionary.CopyTo メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



StringDictionary.CopyTo メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS