ArrayList.Repeat 메서드
요소가 지정된 값의 복사본인 ArrayList를 반환합니다.
네임스페이스: System.Collections
어셈블리: mscorlib(mscorlib.dll)
구문
‘선언
Public Shared Function Repeat ( _
value As Object, _
count As Integer _
) As ArrayList
‘사용 방법
Dim value As Object
Dim count As Integer
Dim returnValue As ArrayList
returnValue = ArrayList.Repeat(value, count)
public static ArrayList Repeat (
Object value,
int count
)
public:
static ArrayList^ Repeat (
Object^ value,
int count
)
public static ArrayList Repeat (
Object value,
int count
)
public static function Repeat (
value : Object,
count : int
) : ArrayList
매개 변수
- count
value가 복사되어야 하는 횟수입니다.
반환 값
모두 value의 복사본에 해당하는 count의 요소 수를 포함하는 ArrayList입니다.
예외
예외 형식 | 조건 |
---|---|
count가 0보다 작은 경우 |
설명
ArrayList은 Null 참조(Visual Basic의 경우 Nothing)을 유효한 값으로 받아들이며 중복 요소를 허용합니다.
이 메서드는 O(n) 연산이며, 여기서 n은 count입니다.
예제
다음 코드 예제에서는 같은 값으로 새 ArrayList를 만들고 초기화하는 방법을 보여 줍니다.
Imports System
Imports System.Collections
Imports Microsoft.VisualBasic
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 'Main
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 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
*/
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
*/
import System.*;
import System.Collections.*;
public class SamplesArrayList
{
public static void main(String[] args)
{
// 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}", (Int32)myAL.get_Count());
Console.WriteLine(" Capacity : {0}", (Int32)myAL.get_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}", (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 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
*/
import System;
import System.Collections;
// Creates a new ArrayList with five elements and initialize each element with a null value.
var myAL : ArrayList = 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 );
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 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
*/
플랫폼
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.
버전 정보
.NET Framework
2.0, 1.1, 1.0에서 지원