ArrayList.AddRange(ICollection) Yöntem
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
öğesinin ICollection öğelerini öğesinin ArrayListsonuna ekler.
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)
Parametreler
öğelerinin ICollection sonuna ArrayListeklenmesi gereken öğesidir. Koleksiyonun kendisi olamaz null, ancak olan nullöğeleri içerebilir.
Özel durumlar
c, null'e eşittir.
Örnekler
Aşağıdaki kod örneğinde öğesine nasıl öğe ekleneceği gösterilmektedir 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
Açıklamalar
ArrayList geçerli bir değer olarak kabul eder null ve yinelenen öğelere izin verir.
içindeki ICollection öğelerin sırası içinde ArrayListkorunur.
Yeni Count (geçerli Count artı koleksiyonun boyutu) değerinden büyükse Capacity, yeni öğelere uyum sağlamak için iç dizi otomatik olarak yeniden yerleştirilerek öğesinin kapasitesi ArrayList artırılır ve yeni öğeler eklenmeden önce var olan öğeler yeni diziye kopyalanır.
ArrayList, öğesini artırmadan Capacityyeni öğeleri barındırabiliyorsa, bu yöntem eklenecek öğe sayısı olan n bir O(n) işlemdir. Yeni öğeleri barındırmak için kapasitenin artırılması gerekiyorsa, bu yöntem bir O(n + m) işlem haline gelir; burada n eklenecek öğe sayısı ve m olur Count.