ArrayList.Repeat(Object, Int32) 메서드

정의

요소가 지정된 값의 복사본인 ArrayList를 반환합니다.

public:
 static System::Collections::ArrayList ^ Repeat(System::Object ^ value, int count);
public static System.Collections.ArrayList Repeat (object value, int count);
public static System.Collections.ArrayList Repeat (object? value, int count);
static member Repeat : obj * int -> System.Collections.ArrayList
Public Shared Function Repeat (value As Object, count As Integer) As ArrayList

매개 변수

value
Object

ArrayList에서 여러 번 복사할 Object입니다. 값은 null이 될 수 있습니다.

count
Int32

value이(가) 복사되어야 하는 횟수입니다.

반환

ArrayList

모두 value의 복사본에 해당하는 count개의 요소가 포함된 ArrayList입니다.

예외

count가 0보다 작은 경우

예제

다음 코드 예제에서는 동일한 값으로 새로 ArrayList 만들고 초기화하는 방법을 보여줍니다.

using namespace System;
using namespace System::Collections;
void PrintValues( IEnumerable^ myList );
int main()
{
   
   // Creates a new ArrayList with five elements and initialize each element with a null value.
   ArrayList^ myAL = ArrayList::Repeat( 0, 5 );
   
   // Displays the count, capacity and values of the ArrayList.
   Console::WriteLine( "ArrayList with five elements with a null value" );
   Console::WriteLine( "   Count    : {0}", myAL->Count );
   Console::WriteLine( "   Capacity : {0}", myAL->Capacity );
   Console::Write( "   Values:" );
   PrintValues( myAL );
   
   // Creates a new ArrayList with seven elements and initialize each element with the string "abc".
   myAL = ArrayList::Repeat( "abc", 7 );
   
   // Displays the count, capacity and values of the ArrayList.
   Console::WriteLine( "ArrayList with seven elements with a string value" );
   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 the following output.
 
 ArrayList with five elements with a null value
    Count    : 5
    Capacity : 16
    Values:
 ArrayList with seven elements with a string value
    Count    : 7
    Capacity : 16
    Values:   abc   abc   abc   abc   abc   abc   abc

 */
using System;
using System.Collections;
public class SamplesArrayList  {

   public static void Main()  {

      // Creates a new ArrayList with five elements and initialize each element with a null value.
      ArrayList myAL = ArrayList.Repeat( null, 5 );

      // Displays the count, capacity and values of the ArrayList.
      Console.WriteLine( "ArrayList with five elements with a null value" );
      Console.WriteLine( "   Count    : {0}", myAL.Count );
      Console.WriteLine( "   Capacity : {0}", myAL.Capacity );
      Console.Write( "   Values:" );
      PrintValues( myAL );

      // Creates a new ArrayList with seven elements and initialize each element with the string "abc".
      myAL = ArrayList.Repeat( "abc", 7 );

      // Displays the count, capacity and values of the ArrayList.
      Console.WriteLine( "ArrayList with seven elements with a string value" );
      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 the following output.

ArrayList with five elements with a null value
   Count    : 5
   Capacity : 16
   Values:
ArrayList with seven elements with a string value
   Count    : 7
   Capacity : 16
   Values:   abc   abc   abc   abc   abc   abc   abc

*/
Imports System.Collections

Public Class SamplesArrayList    

    Public Shared Sub Main()

        ' Creates a new ArrayList with five elements and initialize each
        ' element with a null value.
        Dim myAL As ArrayList = ArrayList.Repeat(Nothing, 5)

        ' Displays the count, capacity and values of the ArrayList.
        Console.WriteLine("ArrayList with five elements with a null value")
        Console.WriteLine("   Count    : {0}", myAL.Count)
        Console.WriteLine("   Capacity : {0}", myAL.Capacity)
        Console.Write("   Values:")
        PrintValues(myAL)

        ' Creates a new ArrayList with seven elements and initialize each
        ' element with the string "abc".
        myAL = ArrayList.Repeat("abc", 7)

        ' Displays the count, capacity and values of the ArrayList.
        Console.WriteLine("ArrayList with seven elements with a string value")
        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

End Class


' This code produces the following output.
' 
' ArrayList with five elements with a null value
'    Count    : 5
'    Capacity : 16
'    Values:					
' ArrayList with seven elements with a string value
'    Count    : 7
'    Capacity : 16
'    Values:	abc	abc	abc	abc	abc	abc	abc

설명

ArrayListnull 유효한 값으로 허용되고 중복 요소를 허용합니다.

이 메서드는 O(n) 작업입니다 n count.

적용 대상