StringCollection.AddRange メソッド
アセンブリ: System (system.dll 内)



StringCollection は、null 参照 (Visual Basic では Nothing) を有効な値として受け取り、要素の重複を許可します。
容量を増やさずに新しい要素を StringCollection に格納できる場合、このメソッドは O(n) 操作になります。ここで、n は、追加する要素の数です。新しい要素を格納するために容量を増やす必要がある場合、このメソッドは O(n + m) 操作になります。ここで、n は追加する要素の数、m は Count です。

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

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からStringCollection.AddRange メソッドを検索する場合は、下記のリンクをクリックしてください。

- StringCollection.AddRange メソッドのページへのリンク