ArrayList.Repeat メソッドとは? わかりやすく解説

ArrayList.Repeat メソッド

要素指定した値のコピーである ArrayList返します

名前空間: System.Collections
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Shared Function Repeat
 ( _
    value As Object, _
    count As Integer _
) As ArrayList

パラメータ

value

新しい ArrayList で複数コピーする Object。値は null 参照 (Visual Basic では Nothing) に設定できます

count

valueコピーする回数

戻り値
count 個の要素がある ArrayList要素はすべて valueコピーです。

例外例外
例外種類条件

ArgumentOutOfRangeException

count が 0 未満です。

解説解説

ArrayList は、null 参照 (Visual Basic では Nothing) を有効な値として受け取り要素重複許可します

このメソッドは O(n) 操作です。ここで、ncount です。

使用例使用例

同一の値を使用して新し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
 */ 
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

ArrayList.Repeat メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ArrayList.Repeat メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS