ArrayList.AddRange(ICollection) 메서드

정의

의 끝에 ICollection요소를 ArrayList 추가합니다.

public:
 virtual void AddRange(System::Collections::ICollection ^ c);
public virtual void AddRange(System.Collections.ICollection c);
abstract member AddRange : System.Collections.ICollection -> unit
override this.AddRange : System.Collections.ICollection -> unit
Public Overridable Sub AddRange (c As ICollection)

매개 변수

c
ICollection

요소가 . ICollectionArrayList끝에 추가되어야 하는 요소입니다. 컬렉션 자체는 사용할 null수 없지만 해당 요소가 null포함될 수 있습니다.

예외

cnull입니다.

읽기 ArrayList 전용입니다.

-또는-

크기가 ArrayList 고정되어 있습니다.

예제

다음 코드 예제에서는 요소를 추가 하는 방법을 보여 있습니다 ArrayList.

using System;
using System.Collections;
public class SamplesArrayList  {

   public static void Main()  {

      // Creates and initializes a new ArrayList.
      ArrayList myAL = new ArrayList();
      myAL.Add( "The" );
      myAL.Add( "quick" );
      myAL.Add( "brown" );
      myAL.Add( "fox" );

      // Creates and initializes a new Queue.
      Queue myQueue = new Queue();
      myQueue.Enqueue( "jumps" );
      myQueue.Enqueue( "over" );
      myQueue.Enqueue( "the" );
      myQueue.Enqueue( "lazy" );
      myQueue.Enqueue( "dog" );

      // Displays the ArrayList and the Queue.
      Console.WriteLine( "The ArrayList initially contains the following:" );
      PrintValues( myAL, '\t' );
      Console.WriteLine( "The Queue initially contains the following:" );
      PrintValues( myQueue, '\t' );

      // Copies the Queue elements to the end of the ArrayList.
      myAL.AddRange( myQueue );

      // Displays the ArrayList.
      Console.WriteLine( "The ArrayList now contains the following:" );
      PrintValues( myAL, '\t' );
   }

   public static void PrintValues( IEnumerable myList, char mySeparator )  {
      foreach ( Object obj in myList )
         Console.Write( "{0}{1}", mySeparator, obj );
      Console.WriteLine();
   }
}


/*
This code produces the following output.

The ArrayList initially contains the following:
    The    quick    brown    fox
The Queue initially contains the following:
    jumps    over    the    lazy    dog
The ArrayList now contains the following:
    The    quick    brown    fox    jumps    over    the    lazy    dog
*/
Imports System.Collections

Public Class SamplesArrayList    
    
    Public Shared Sub Main()
        
        ' Creates and initializes a new ArrayList.
        Dim myAL As New ArrayList()
        myAL.Add("The")
        myAL.Add("quick")
        myAL.Add("brown")
        myAL.Add("fox")
        
        ' Creates and initializes a new Queue.
        Dim myQueue As New Queue()
        myQueue.Enqueue("jumps")
        myQueue.Enqueue("over")
        myQueue.Enqueue("the")
        myQueue.Enqueue("lazy")
        myQueue.Enqueue("dog")
        
        ' Displays the ArrayList and the Queue.
        Console.WriteLine("The ArrayList initially contains the following:")
        PrintValues(myAL, ControlChars.Tab)
        Console.WriteLine("The Queue initially contains the following:")
        PrintValues(myQueue, ControlChars.Tab)
        
        ' Copies the Queue elements to the end of the ArrayList.
        myAL.AddRange(myQueue)
        
        ' Displays the ArrayList.
        Console.WriteLine("The ArrayList now contains the following:")
        PrintValues(myAL, ControlChars.Tab)
    End Sub

    Public Shared Sub PrintValues(myList As IEnumerable, mySeparator As Char)
        Dim obj As [Object]
        For Each obj In  myList
          Console.Write( "{0}{1}", mySeparator, obj )
        Next obj
        Console.WriteLine()
    End Sub

End Class


' This code produces the following output.
' 
' The ArrayList initially contains the following:
'     The    quick    brown    fox
' The Queue initially contains the following:
'     jumps    over    the    lazy    dog
' The ArrayList now contains the following:
'     The    quick    brown    fox    jumps    over    the    lazy    dog

설명

ArrayListnull 유효한 값으로 허용되고 중복 요소를 허용합니다.

에 있는 ICollection 요소의 순서는 에 유지됩니다 ArrayList.

Count 요소(컬렉션의 현재 Count 및 크기)가 보다 Capacity크면 새 요소를 수용하도록 내부 배열을 자동으로 다시 할당하여 용량 ArrayList 이 증가하고 새 요소가 추가되기 전에 기존 요소가 새 배열에 복사됩니다.

ArrayList 새 요소를 늘리Capacity지 않고 수용할 수 있는 경우 이 메서드는 O(n) 추가할 요소의 수가 있는 n 작업입니다. 새 요소를 수용하기 위해 용량을 늘려야 하는 경우 이 메서드는 추가될 요소의 수인 mCount작업이 n 됩니다O(n + m).

적용 대상

추가 정보