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

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

StringCollection.AddRange メソッド

文字列配列要素StringCollection末尾コピーします

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

Public Sub AddRange ( _
    value As String() _
)
Dim instance As StringCollection
Dim value As String()

instance.AddRange(value)
public void AddRange (
    string[] value
)
public:
void AddRange (
    array<String^>^ value
)
public void AddRange (
    String[] value
)

パラメータ

value

StringCollection の末尾追加する文字列配列配列自体null 参照 (Visual Basic では Nothing) にすることはできませんが、配列格納する要素null 参照 (Visual Basic では Nothing) であってもかまいません

例外例外
例外種類条件

ArgumentNullException

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

解説解説

StringCollection は、null 参照 (Visual Basic では Nothing) を有効な値として受け取り要素重複許可します

容量を増やさずに新し要素StringCollection格納できる場合、このメソッドは O(n) 操作なります。ここで、n は、追加する要素の数です。新し要素格納するために容量増やす必要がある場合、このメソッドは O(n + m) 操作なります。ここで、n追加する要素の数、mCount です。

使用例使用例

StringCollection新し要素追加するコード例次に示します

Imports System
Imports System.Collections
Imports System.Collections.Specialized

Public Class SamplesStringCollection   

   Public Shared Sub Main()

      ' Creates and initializes a new StringCollection.
      Dim myCol As New StringCollection()

      Console.WriteLine("Initial contents of the StringCollection:")
      PrintValues(myCol)

      ' Adds a range of elements from an array to the end of the StringCollection.
      Dim myArr() As [String] = {"RED",
 "orange", "yellow",
 "RED", "green", "blue", "RED", "indigo",
 "violet", "RED"}
      myCol.AddRange(myArr)

      Console.WriteLine("After adding a range of elements:")
      PrintValues(myCol)

      ' Adds one element to the end of the StringCollection and inserts
 another at index 3.
      myCol.Add("* white")
      myCol.Insert(3, "* gray")

      Console.WriteLine("After adding ""*
 white"" to the end and inserting ""*
 gray"" at index 3:")
      PrintValues(myCol)

   End Sub 'Main

   Public Shared Sub PrintValues(myCol
 As IEnumerable)
      Dim obj As [Object]
      For Each obj In  myCol
         Console.WriteLine("   {0}", obj)
      Next obj
      Console.WriteLine()
   End Sub 'PrintValues

End Class 'SamplesStringCollection
 


'This code produces the following output.
'
'Initial contents of the StringCollection:
'
'After adding a range of elements:
'   RED
'   orange
'   yellow
'   RED
'   green
'   blue
'   RED
'   indigo
'   violet
'   RED
'
'After adding "* white" to the end and inserting "* gray"
 at index 3:
'   RED
'   orange
'   yellow
'   * gray
'   RED
'   green
'   blue
'   RED
'   indigo
'   violet
'   RED
'   * white
'

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

public class SamplesStringCollection  {

   public static void Main()
  {

      // Creates and initializes a new StringCollection.
      StringCollection myCol = new StringCollection();

      Console.WriteLine( "Initial contents of the StringCollection:" );
      PrintValues( myCol );

      // Adds a range of elements from an array to the end of the StringCollection.
      String[] myArr = new String[] { "RED", "orange",
 "yellow", "RED", "green", "blue", "RED",
 "indigo", "violet", "RED" };
      myCol.AddRange( myArr );

      Console.WriteLine( "After adding a range of elements:" );
      PrintValues( myCol );

      // Adds one element to the end of the StringCollection and inserts
 another at index 3.
      myCol.Add( "* white" );
      myCol.Insert( 3, "* gray" );

      Console.WriteLine( "After adding \"* white\" to the end and
 inserting \"* gray\" at index 3:" );
      PrintValues( myCol );

   }

   public static void PrintValues(
 IEnumerable myCol )  {
      foreach ( Object obj in myCol )
         Console.WriteLine( "   {0}", obj );
      Console.WriteLine();
   }

}

/*
This code produces the following output.

Initial contents of the StringCollection:

After adding a range of elements:
   RED
   orange
   yellow
   RED
   green
   blue
   RED
   indigo
   violet
   RED

After adding "* white" to the end and inserting "* gray" at index
 3:
   RED
   orange
   yellow
   * gray
   RED
   green
   blue
   RED
   indigo
   violet
   RED
   * white

*/
#using <System.dll>

using namespace System;
using namespace System::Collections;
using namespace System::Collections::Specialized;
void PrintValues( IEnumerable^ myCol );
int main()
{
   
   // Creates and initializes a new StringCollection.
   StringCollection^ myCol = gcnew StringCollection;
   Console::WriteLine( "Initial contents of the StringCollection:" );
   PrintValues( myCol );
   
   // Adds a range of elements from an array to the end of the StringCollection.
   array<String^>^myArr = {"RED","orange","yellow"
,"RED","green","blue","RED","indigo"
,"violet","RED"};
   myCol->AddRange( myArr );
   Console::WriteLine( "After adding a range of elements:" );
   PrintValues( myCol );
   
   // Adds one element to the end of the StringCollection and inserts
 another at index 3.
   myCol->Add( "* white" );
   myCol->Insert( 3, "* gray" );
   Console::WriteLine( "After adding \"* white\" to the end and inserting
 \"* gray\" at index 3:" );
   PrintValues( myCol );
}

void PrintValues( IEnumerable^ myCol )
{
   IEnumerator^ myEnum = myCol->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      Object^ obj = safe_cast<Object^>(myEnum->Current);
      Console::WriteLine( "   {0}", obj );
   }

   Console::WriteLine();
}

/*
This code produces the following output.

Initial contents of the StringCollection:

After adding a range of elements:
   RED
   orange
   yellow
   RED
   green
   blue
   RED
   indigo
   violet
   RED

After adding "* white" to the end and inserting "* gray" at index
 3:
   RED
   orange
   yellow
   * gray
   RED
   green
   blue
   RED
   indigo
   violet
   RED
   * white

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

public class SamplesStringCollection
{      
    public static void main(String[]
 args)
    {        
        // Creates and initializes a new StringCollection.
        StringCollection myCol =  new StringCollection();
        
        Console.WriteLine("Initial contents of the StringCollection:");
        PrintValues(myCol);
        
        // Adds a range of elements from an array to the end of the
 
        // StringCollection.
        String myArr[] = new String[]{"RED", "orange",
 "yellow", "RED", 
            "green", "blue", "RED", "indigo",
 "violet", "RED"};
        myCol.AddRange(myArr);
        
        Console.WriteLine("After adding a range of elements:");
        PrintValues(myCol);
        
        // Adds one element to the end of the StringCollection and inserts
        // another at index 3.
        myCol.Add("* white");
        myCol.Insert(3, "* gray");
        
        Console.WriteLine("After adding \"* white\" to the end and
 inserting"
            + " \"* gray\" at index 3:");
        PrintValues(myCol);
    } //main

    public static void PrintValues(IEnumerable
 myCol) 
    {
        Object obj = null;
        IEnumerator objEnum = myCol.GetEnumerator();

        while (objEnum.MoveNext()) { 
            obj = objEnum.get_Current();
            Console.WriteLine("   {0}", obj);
        }

        Console.WriteLine();
    } //PrintValues
} //SamplesStringCollection 

/*
This code produces the following output.

Initial contents of the StringCollection:

After adding a range of elements:
   RED
   orange
   yellow
   RED
   green
   blue
   RED
   indigo
   violet
   RED

After adding "* white" to the end and inserting "* gray" at index
 3:
   RED
   orange
   yellow
   * gray
   RED
   green
   blue
   RED
   indigo
   violet
   RED
   * white

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



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

辞書ショートカット

すべての辞書の索引

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

   

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



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

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

©2024 GRAS Group, Inc.RSS