ArrayList, classe (System.Collections)

Bibliothèque de classes .NET Framework 
ArrayList, classe 

Implémente l'interface IList à l'aide d'un tableau dont la taille augmente dynamiquement selon les besoins.

Espace de noms : System.Collections
Assembly : mscorlib (dans mscorlib.dll)

SyntaxeSyntaxe


Visual Basic (Déclaration)
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public Class ArrayList
    Implements IList, ICollection, IEnumerable, ICloneable


Visual Basic (Utilisation)
Dim instance As ArrayList


C#
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public class ArrayList : IList, ICollection, IEnumerable, 
    ICloneable


C++
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public ref class ArrayList : IList, ICollection, IEnumerable, 
    ICloneable


J#
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public class ArrayList implements IList, ICollection, 
    IEnumerable, ICloneable


JScript
SerializableAttribute 
ComVisibleAttribute(true) 
public class ArrayList implements IList, ICollection, 
    IEnumerable, ICloneable
NotesNotes

Le tri du ArrayList n'est pas garanti. Vous devez trier le ArrayList avant d'exécuter des opérations (telles que BinarySearch) qui exigent le tri du ArrayList.

La capacité de ArrayList correspond au nombre d'éléments que peut contenir ArrayList. La capacité initiale par défaut de ArrayList est 0. Lorsque des éléments sont ajoutés à ArrayList, la capacité augmente automatiquement par réallocation. La capacité peut être diminuée en appelant TrimToSize ou en définissant explicitement la propriété Capacity.

Il est possible d'accéder aux éléments de cette collection en utilisant un index d'entiers. Les index de cette collection sont des index de base zéro.

ArrayList accepte référence Null (Nothing en Visual Basic) comme valeur valide et autorise les éléments en double.

ExempleExemple

L'exemple de code suivant montre comment créer et initialiser un ArrayList et comment afficher ses valeurs.



Visual Basic
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("Hello")
        myAL.Add("World")
        myAL.Add("!")
        
        ' Displays the properties and values of the ArrayList.
        Console.WriteLine("myAL")
        Console.WriteLine("    Count:    {0}", myAL.Count)
        Console.WriteLine("    Capacity: {0}", myAL.Capacity)
        Console.Write("    Values:")
        PrintValues(myAL)
    End Sub

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

End Class


' This code produces output similar to the following:
' 
' myAL
'     Count:    3
'     Capacity: 4
'     Values:   Hello   World   !



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

   public static void Main()  {

      // Creates and initializes a new ArrayList.
      ArrayList myAL = new ArrayList();
      myAL.Add("Hello");
      myAL.Add("World");
      myAL.Add("!");

      // Displays the properties and values of the ArrayList.
      Console.WriteLine( "myAL" );
      Console.WriteLine( "    Count:    {0}", myAL.Count );
      Console.WriteLine( "    Capacity: {0}", myAL.Capacity );
      Console.Write( "    Values:" );
      PrintValues( myAL );
   }

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

}


/* 
This code produces output similar to the following:

myAL
    Count:    3
    Capacity: f
    Values:   Hello   World   !

*/


C++
using namespace System;
using namespace System::Collections;
void PrintValues( IEnumerable^ myList );
int main()
{
   
   // Creates and initializes a new ArrayList.
   ArrayList^ myAL = gcnew ArrayList;
   myAL->Add( "Hello" );
   myAL->Add( "World" );
   myAL->Add( "!" );
   
   // Displays the properties and values of the ArrayList.
   Console::WriteLine( "myAL" );
   Console::WriteLine( "    Count:    {0}", myAL->Count );
   Console::WriteLine( "    Capacity: {0}", myAL->Capacity );
   Console::Write( "    Values:" );
   PrintValues( myAL );
}

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

   Console::WriteLine();
}

/* 
This code produces output similar to the following:

myAL
    Count:    3
    Capacity: 4
    Values:   Hello   World   !

*/


J#
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("Hello");
        myAL.Add("World");
        myAL.Add("!");

        // Displays the properties and values of the ArrayList.
        Console.WriteLine("myAL");
        Console.WriteLine("    Count:    {0}", (Int32)myAL.get_Count());
        Console.WriteLine("    Capacity: {0}", (Int32)myAL.get_Capacity());
        Console.Write("    Values:");
        PrintValues(myAL);
    } //main

    public static void PrintValues(IEnumerable myList)
    {
        IEnumerator objMyEnum = myList.GetEnumerator();
        while (objMyEnum.MoveNext()) {
            Object obj = objMyEnum.get_Current();
            Console.Write("   {0}", obj);
        }
        Console.WriteLine();
    } //PrintValues
} //SamplesArrayList 
/* 
 This code produces output similar to the following:
 
 myAL
     Count:    3
     Capacity: 4
     Values:   Hello   World   !

 */


JScript
import System;
import System.Collections;

// Creates and initializes a new ArrayList.
var myAL : ArrayList = new ArrayList();
myAL.Add("Hello");
myAL.Add("World");
myAL.Add("!");

// Displays the properties and values of the ArrayList.
Console.WriteLine( "myAL" );
Console.WriteLine( "\tCount:    {0}", myAL.Count );
Console.WriteLine( "\tCapacity: {0}", myAL.Capacity );
Console.Write( "\tValues:" );
PrintValues( myAL );

 
function PrintValues( myList : IEnumerable )  {
   var myEnumerator : System.Collections.IEnumerator = myList.GetEnumerator();
   while ( myEnumerator.MoveNext() )
      Console.Write( "\t{0}", myEnumerator.Current );
   Console.WriteLine();
}
 /* 
 This code produces output similar to the following:
 
 myAL
     Count:    3
     Capacity: 4
     Values:    Hello    World    !
 */
Hiérarchie d'héritageHiérarchie d'héritage
Sécurité des threadsSécurité des threads

Les membres statiques publics (Shared en Visual Basic) de ce type sont thread-safe. Il n'est pas garanti que les membres d'instance soient thread-safe.

ArrayList peut prendre en charge plusieurs opérations de lecture simultanées, tant que la collection n'est pas modifiée. Afin de garantir la sécurité des threads de ArrayList, toutes les opérations doivent être effectuées par l'intermédiaire du wrapper retourné par la méthode Synchronized.

L'énumération d'une collection n'est intrinsèquement pas une procédure thread-safe. Même lorsqu'une collection est synchronisée, les autres threads peuvent toujours modifier la collection, ce qui entraîne la levée d'une exception par l'énumérateur. Pour garantir la sécurité des threads au cours de l'énumération, vous pouvez soit verrouiller la collection pendant l'ensemble de l'énumération, soit intercepter les exceptions résultant des modifications apportées par les autres threads.

Plates-formesPlates-formes

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile pour Pocket PC, Windows Mobile pour Smartphone, Windows Server 2003, Windows XP Édition Media Center, Windows XP Professionnel Édition x64, Windows XP SP2, Windows XP Starter Edition

Le .NET Framework ne prend pas en charge toutes les versions de chaque plate-forme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise.

Informations de versionInformations de version

.NET Framework

Prise en charge dans : 2.0, 1.1, 1.0

.NET Compact Framework

Prise en charge dans : 2.0, 1.0
Voir aussiVoir aussi

Ces informations proviennent du site de http://msdn2.microsoft.com
Source de cette page : http://msdn2.microsoft.com/fr-fr/library/system.collections.arraylist.aspx

Réseaux sociaux

Vous pouvez modifier vos préférences dans votre profil pour ne plus afficher les interactions avec les réseaux sociaux sur ces pages.

 

Nuage de mots clés

13 mots clés dont 0 définis manuellement (plus d'information...).

Avertissement

Cette page ne possède pas encore de mots clés manuels, ceci est donc un exemple automatique (les niveaux de pertinence sont fictifs, mais les liens sont valables). Pour tester le nuage avec une page qui contient des mots définis manuellement, vous pouvez cliquer ici.

Vous pouvez modifier vos préférences dans votre profil pour ne plus afficher le nuage de mots clés.

 

Astuce pour imprimer les couleurs des cellules de tableaux : http://www.gaudry.be/ast-rf-450.html
Aucun commentaire pour cette page

© Ce document issu de l′infobrol est enregistré sous le certificat Cyber PrInterDeposit Digital Numbertection. Enregistrement IDDN n° 5329-4300
Document créé le 07/10/06 12:07, dernière modification le Vendredi 17 Juin 2011, 12:11
Source du document imprimé : http://www.gaudry.be/dotnet-rf-system.collections.arraylist.html Document affiché 4 fois ce mois de Mai.
St.Gaudry©07.01.02
Outils (masquer)
||
Recherche (afficher)
Recherche :

Utilisateur (masquer)
Apparence (afficher)
Stats (afficher)
15832 documents
452 astuces.
549 niouzes.
3099 definitions.
447 membres.
8115 messages.

Document genere en :
0,48 seconde

Mises à jour :
Mises à jour du site
Citation (masquer)
Certaines personnes portent un pyjama Superman. Superman porte un pyjama Chuck Norris.

Anonyme [Chuck Norris fact]
 
l'infobrol
Nous sommes le Jeudi 31 Mai 2012, 18:50, toutes les heures sont au format GMT+1.00 Heure, heure d'été (+1)