Return an ArrayList whose elements are copies of the specified value in CSharp

Description

The following code shows how to return an ArrayList whose elements are copies of the specified value.

Example


/*  w  w  w.j  a  va  2  s  .  c  o m*/
using System;
using System.Collections;
public class SamplesArrayList  {

   public static void Main()  {
      ArrayList myAL = ArrayList.Repeat( null, 5 );

      Console.WriteLine(myAL.Count );
      Console.WriteLine(myAL.Capacity );

      foreach ( Object obj in myAL ){
         Console.WriteLine(obj );
      }


      myAL = ArrayList.Repeat( "abc", 7 );

      Console.WriteLine(myAL.Count );
      Console.WriteLine(myAL.Capacity );

      foreach ( Object obj in myAL ){
         Console.WriteLine(obj );
      }
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Collections »




ArrayList
BitArray
Collection
Comparer
HashSet
Hashtable
LinkedList
List
ListDictionary
OrderedDictionary
Queue
SortedList
SortedSet
Stack
StringCollection
StringDictionary