ArrayList.Repeat(Object, Int32) メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
指定した値のコピーである要素を持つ 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
パラメーター
- count
- Int32
value
をコピーする回数。
戻り値
count
個の要素があり、その要素がすべて value
のコピーである 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
注釈
ArrayList は null
有効な値として受け取り、重複する要素を許可します。
このメソッドは 操作です O(n)
。ここで n
、 は count
です。
適用対象
GitHub で Microsoft と共同作業する
このコンテンツのソースは GitHub にあります。そこで、issue や pull request を作成および確認することもできます。 詳細については、共同作成者ガイドを参照してください。
.NET