ArrayList.AddRange 메서드
ArrayList의 끝에 ICollection의 요소를 복사합니다.
네임스페이스: System.Collections
어셈블리: mscorlib(mscorlib.dll)
구문
‘선언
Public Overridable Sub AddRange ( _
c As ICollection _
)
‘사용 방법
Dim instance As ArrayList
Dim c As ICollection
instance.AddRange(c)
public virtual void AddRange (
ICollection c
)
public:
virtual void AddRange (
ICollection^ c
)
public void AddRange (
ICollection c
)
public function AddRange (
c : ICollection
)
매개 변수
- c
요소가 ArrayList의 끝에 추가되어야 하는 ICollection입니다. 컬렉션 자체가 Null 참조(Visual Basic의 경우 Nothing)일 수는 없지만 Null 참조(Visual Basic의 경우 Nothing)인 요소를 포함할 수는 있습니다.
예외
예외 형식 | 조건 |
---|---|
c가 Null 참조(Visual Basic의 경우 Nothing)인 경우 |
|
ArrayList가 읽기 전용인 경우 - 또는 - ArrayList의 크기가 고정되어 있는 경우 |
설명
ArrayList은 Null 참조(Visual Basic의 경우 Nothing)을 유효한 값으로 받아들이며 중복 요소를 허용합니다.
ICollection의 요소 순서는 ArrayList에서 유지됩니다.
새 Count(현재 Count에 컬렉션의 크기를 더한 값)가 Capacity보다 크면 ArrayList의 용량이 새 요소를 수용하기 위해 내부 배열을 자동으로 재할당하여 증가하며 기존 요소가 새 배열로 복사된 후 새 요소가 추가됩니다.
ArrayList가 Capacity를 증가시키지 않고 새 요소를 수용할 수 있으면 이 메서드는 O(n) 연산이 됩니다. 여기에서 n은 추가될 요소의 수입니다. 용량을 증가시켜 새 요소를 수용해야 하는 경우 이 메서드는 O(n + m) 연산이 됩니다. 여기에서 n은 추가될 요소의 수이고 m은 Count를 나타냅니다.
예제
다음 코드 예제에서는 ArrayList에 요소를 추가하는 방법을 보여 줍니다.
Imports System
Imports System.Collections
Imports Microsoft.VisualBasic
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("jumped")
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 'PrintValues
End Class
' This code produces the following output.
'
' The ArrayList initially contains the following:
' The quick brown fox
' The Queue initially contains the following:
' jumped over the lazy dog
' The ArrayList now contains the following:
' The quick brown fox jumped over the lazy dog
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( "jumped" );
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:
jumped over the lazy dog
The ArrayList now contains the following:
The quick brown fox jumped over the lazy dog
*/
using namespace System;
using namespace System::Collections;
void PrintValues( IEnumerable^ myList, char mySeparator );
int main()
{
// Creates and initializes a new ArrayList.
ArrayList^ myAL = gcnew ArrayList;
myAL->Add( "The" );
myAL->Add( "quick" );
myAL->Add( "brown" );
myAL->Add( "fox" );
// Creates and initializes a new Queue.
Queue^ myQueue = gcnew Queue;
myQueue->Enqueue( "jumped" );
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' );
}
void PrintValues( IEnumerable^ myList, char mySeparator )
{
IEnumerator^ myEnum = myList->GetEnumerator();
while ( myEnum->MoveNext() )
{
Object^ obj = safe_cast<Object^>(myEnum->Current);
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:
jumped over the lazy dog
The ArrayList now contains the following:
The quick brown fox jumped over the lazy dog
*/
import System.*;
import System.Collections.*;
public class SamplesArrayList
{
public static void main(String[] args)
{
// 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("jumped");
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');
} //main
public static void PrintValues(IEnumerable myList, char mySeparator)
{
IEnumerator objMyEnum = myList.GetEnumerator();
while (objMyEnum.MoveNext()) {
Object obj = objMyEnum.get_Current();
Console.Write("{0}{1}",(Char)mySeparator, obj);
}
Console.WriteLine();
} //PrintValues
} //SamplesArrayList
/*
This code produces the following output.
The ArrayList initially contains the following:
The quick brown fox
The Queue initially contains the following:
jumped over the lazy dog
The ArrayList now contains the following:
The quick brown fox jumped over the lazy dog
*/
import System;
import System.Collections;
// Creates and initializes a new ArrayList.
var myAL : ArrayList = new ArrayList();
myAL.Add( "The" );
myAL.Add( "quick" );
myAL.Add( "brown" );
myAL.Add( "fox" );
// Creates and initializes a new Queue.
var myQueue : Queue = new Queue();
myQueue.Enqueue( "jumped" );
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' );
function PrintValues( myList : IEnumerable , mySeparator : char ) {
var myEnumerator : System.Collections.IEnumerator = myList.GetEnumerator();
while ( myEnumerator.MoveNext() )
Console.Write( "{0}{1}", mySeparator, myEnumerator.Current );
Console.WriteLine();
}
/*
This code produces the following output.
The ArrayList initially contains the following:
The quick brown fox
The Queue initially contains the following:
jumped over the lazy dog
The ArrayList now contains the following:
The quick brown fox jumped over the lazy dog
*/
플랫폼
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.
버전 정보
.NET Framework
2.0, 1.1, 1.0에서 지원
.NET Compact Framework
2.0, 1.0에서 지원
참고 항목
참조
ArrayList 클래스
ArrayList 멤버
System.Collections 네임스페이스
ICollection
Capacity
Count
Add
InsertRange
SetRange
GetRange
RemoveRange