C# ArrayList Repeat

Description

ArrayList Repeat returns an ArrayList whose elements are copies of the specified value.

Syntax

ArrayList.Repeat has the following syntax.


public static ArrayList Repeat(
  Object value,
  int count
)

Parameters

ArrayList.Repeat has the following parameters.

  • value - The Object to copy multiple times in the new ArrayList. The value can be null.
  • count - The number of times value should be copied.

Returns

ArrayList.Repeat method returns An ArrayList with count number of elements, all of which are copies of value.

Example

The following code example shows how to create and initialize a new ArrayList with the same value.


/*w ww . j a  v a 2  s.  co 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 );

      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 »
    System.Collections »




ArrayList
BitArray
Comparer
Hashtable
Queue
SortedList
Stack