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

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > ArrayList.GetRange メソッドの意味・解説 

ArrayList.GetRange メソッド

元の ArrayList 内の要素サブセットを表す ArrayList返します

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

Public Overridable Function
 GetRange ( _
    index As Integer, _
    count As Integer _
) As ArrayList
Dim instance As ArrayList
Dim index As Integer
Dim count As Integer
Dim returnValue As ArrayList

returnValue = instance.GetRange(index, count)
public virtual ArrayList GetRange (
    int index,
    int count
)
public:
virtual ArrayList^ GetRange (
    int index, 
    int count
)
public ArrayList GetRange (
    int index, 
    int count
)
public function GetRange (
    index : int, 
    count : int
) : ArrayList

パラメータ

index

範囲開始する位置の、0 から始まる ArrayList のインデックス番号

count

範囲内要素の数。

戻り値
元の ArrayList 内の要素サブセットを表す ArrayList

例外例外
例外種類条件

ArgumentOutOfRangeException

index が 0 未満です。

または

count が 0 未満です。

ArgumentException

index および countArrayList 内の要素の有効範囲示していません。

解説解説

このメソッドは、要素コピー作成しません。新しArrayList は、元の ArrayListビュー ウィンドウにすぎません。ただし、元の ArrayList対す以降変更はすべて、このビュー ウィンドウArrayList使用して行う必要があります直接元の ArrayList変更加えた場合は、ビュー ウィンドウ ArrayList無効になり、ビュー ウィンドウどのような操作行っても InvalidOperationException が返されます。

このメソッドは O(1) 操作です。

使用例使用例

ArrayList一定範囲要素設定または取得する方法次のコード例示します

Imports System
Imports System.Collections

Public Class SamplesArrayList

    Public Shared Sub Main()

        ' Creates and initializes a new ArrayList.
        Dim myAL As New
 ArrayList()
        myAL.Add("The")
        myAL.Add("quick")
        myAL.Add("brown")
        myAL.Add("fox")
        myAL.Add("jumped")
        myAL.Add("over")
        myAL.Add("the")
        myAL.Add("lazy")
        myAL.Add("dog")

        ' Creates and initializes the source ICollection.
        Dim mySourceList As New
 Queue()
        mySourceList.Enqueue("big")
        mySourceList.Enqueue("gray")
        mySourceList.Enqueue("wolf")

        ' Displays the values of five elements starting at index 0.
        Dim mySubAL As ArrayList = myAL.GetRange(0,
 5)
        Console.WriteLine("Index 0 through 4 contains:")
        PrintValues(mySubAL, vbTab)

        ' Replaces the values of five elements starting at index 1 with
 the values in the ICollection.
        myAL.SetRange(1, mySourceList)

        ' Displays the values of five elements starting at index 0.
        mySubAL = myAL.GetRange(0, 5)
        Console.WriteLine("Index 0 through 4 now contains:")
        PrintValues(mySubAL, vbTab)

    End Sub 'Main

    Public Shared Sub PrintValues(myList
 As IEnumerable, mySeparator As Char)
        Dim obj As [Object]
        For Each obj In
  myList
            Console.Write("{0}{1}", mySeparator, obj)
        Next obj
        Console.WriteLine()
    End Sub 'PrintValues

End Class 'SamplesArrayList 


' This code produces the following output.
' 
' Index 0 through 4 contains:
'         The     quick   brown   fox     jumped
' Index 0 through 4 now contains:
'         The     big     gray    wolf    jumped

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

   public static void Main()
  {

      // Creates and initializes a new ArrayList.
      ArrayList myAL = new ArrayList();
      myAL.Add( "The" );
      myAL.Add( "quick" );
      myAL.Add( "brown" );
      myAL.Add( "fox" );
      myAL.Add( "jumped" );
      myAL.Add( "over" );
      myAL.Add( "the" );
      myAL.Add( "lazy" );
      myAL.Add( "dog" );

      // Creates and initializes the source ICollection.
      Queue mySourceList = new Queue();
      mySourceList.Enqueue( "big" );
      mySourceList.Enqueue( "gray" );
      mySourceList.Enqueue( "wolf" );

      // Displays the values of five elements starting at index 0.
      ArrayList mySubAL = myAL.GetRange( 0, 5 );
      Console.WriteLine( "Index 0 through 4 contains:" );
      PrintValues( mySubAL, '\t' );

      // Replaces the values of five elements starting at index 1 with
 the values in the ICollection.
      myAL.SetRange( 1, mySourceList );

      // Displays the values of five elements starting at index 0.
      mySubAL = myAL.GetRange( 0, 5 );
      Console.WriteLine( "Index 0 through 4 now contains:" );
      PrintValues( mySubAL, '\t' );

   }

   public static void PrintValues(
 IEnumerable myList, char mySeparator )  {
      foreach ( Object obj in myList )
         Console.Write( "{0}{1}", mySeparator, obj );
      Console.WriteLine();
   }

}


/* 
This code produces the following output.

Index 0 through 4 contains:
        The     quick   brown   fox     jumped
Index 0 through 4 now contains:
        The     big     gray    wolf    jumped
*/ 
using namespace System;
using namespace System::Collections;
void PrintValues( IEnumerable^ myList, char
 mySeparator );
int main()
{
   
   // Creates and initializes a new ArrayList.
   ArrayList^ myAL = gcnew ArrayList;
   myAL->Add( "The" );
   myAL->Add( "quick" );
   myAL->Add( "brown" );
   myAL->Add( "fox" );
   myAL->Add( "jumped" );
   myAL->Add( "over" );
   myAL->Add( "the" );
   myAL->Add( "lazy" );
   myAL->Add( "dog" );
   
   // Creates and initializes the source ICollection.
   Queue^ mySourceList = gcnew Queue;
   mySourceList->Enqueue( "big" );
   mySourceList->Enqueue( "gray" );
   mySourceList->Enqueue( "wolf" );
   
   // Displays the values of five elements starting at index 0.
   ArrayList^ mySubAL = myAL->GetRange( 0, 5 );
   Console::WriteLine( "Index 0 through 4 contains:" );
   PrintValues( mySubAL, '\t' );
   
   // Replaces the values of five elements starting at index 1 with
 the values in the ICollection.
   myAL->SetRange( 1, mySourceList );
   
   // Displays the values of five elements starting at index 0.
   mySubAL = myAL->GetRange( 0, 5 );
   Console::WriteLine( "Index 0 through 4 now contains:" );
   PrintValues( mySubAL, '\t' );
}

void PrintValues( IEnumerable^ myList, char
 mySeparator )
{
   IEnumerator^ myEnum = myList->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      Object^ obj = safe_cast<Object^>(myEnum->Current);
      Console::Write( "{0}{1}", mySeparator, obj );
   }

   Console::WriteLine();
}

/* 
 This code produces the following output.
 
 Index 0 through 4 contains:
         The     quick   brown   fox     jumped
 Index 0 through 4 now contains:
         The     big     gray    wolf    jumped
 */
import System.*;
import System.Collections.*;

public class SamplesArrayList
{
    public static void main(String[]
 args)
    {
        // Creates and initializes a new ArrayList.
        ArrayList myAL = new ArrayList();

        myAL.Add("The");
        myAL.Add("quick");
        myAL.Add("brown");
        myAL.Add("fox");
        myAL.Add("jumped");
        myAL.Add("over");
        myAL.Add("the");
        myAL.Add("lazy");
        myAL.Add("dog");

        // Creates and initializes the source ICollection.
        Queue mySourceList = new Queue();

        mySourceList.Enqueue("big");
        mySourceList.Enqueue("gray");
        mySourceList.Enqueue("wolf");

        // Displays the values of five elements starting at index 0.
        ArrayList mySubAL = myAL.GetRange(0, 5);

        Console.WriteLine("Index 0 through 4 contains:");
        PrintValues(mySubAL, '\t');

        // Replaces the values of five elements starting at index 1
 with the 
        // values in the ICollection.
        myAL.SetRange(1, mySourceList);

        // Displays the values of five elements starting at index 0.
        mySubAL = myAL.GetRange(0, 5);
        Console.WriteLine("Index 0 through 4 now contains:");
        PrintValues(mySubAL, '\t');
    } //main

    public static void PrintValues(IEnumerable
 myList, char mySeparator)
    {
        IEnumerator objMyEnum = myList.GetEnumerator();
        while (objMyEnum.MoveNext()) {
            Object obj = objMyEnum.get_Current();
            Console.Write("{0}{1}", (Char)mySeparator, obj);
        }
        Console.WriteLine();
    } //PrintValues
} //SamplesArrayList 

/* 
 This code produces the following output.
 
 Index 0 through 4 contains:
         The     quick   brown   fox     jumped
 Index 0 through 4 now contains:
         The     big     gray    wolf    jumped
 */
import System;
import System.Collections;

// Creates and initializes a new ArrayList.
var myAL : ArrayList = new ArrayList();
myAL.Add( "The" );
myAL.Add( "quick" );
myAL.Add( "brown" );
myAL.Add( "fox" );
myAL.Add( "jumped" );
myAL.Add( "over" );
myAL.Add( "the" );
myAL.Add( "lazy" );
myAL.Add( "dog" );

// Creates and initializes the source ICollection.
var mySourceList : Queue = new Queue();
mySourceList.Enqueue( "big" );
mySourceList.Enqueue( "gray" );
mySourceList.Enqueue( "wolf" );

// Displays the values of five elements starting at index 0.
var mySubAL : ArrayList  = myAL.GetRange( 0, 5 );
Console.WriteLine( "Index 0 through 4 contains:" );
PrintValues( mySubAL, '\t' );

// Replaces the values of five elements starting at index 1 with the
 values in the ICollection.
myAL.SetRange( 1, mySourceList );

// Displays the values of five elements starting at index 0.
mySubAL = myAL.GetRange( 0, 5 );
Console.WriteLine( "Index 0 through 4 now contains:" );
PrintValues( mySubAL, '\t' );
 
function PrintValues( myList : IEnumerable, mySeparator : char
  )  {
   var myEnumerator : System.Collections.IEnumerator  = myList.GetEnumerator();
   while ( myEnumerator.MoveNext() )
      Console.Write( "{0}{1}", mySeparator, myEnumerator.Current );
   Console.WriteLine();
}
 /* 
 This code produces the following output.
 
 Index 0 through 4 contains:
     The    quick    brown    fox    jumped
 Index 0 through 4 now contains:
     The    big    gray    wolf    jumped
 */ 
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ArrayList クラス
ArrayList メンバ
System.Collections 名前空間
RemoveRange
AddRange
InsertRange
SetRange


このページでは「.NET Framework クラス ライブラリ リファレンス」からArrayList.GetRange メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からArrayList.GetRange メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からArrayList.GetRange メソッド を検索

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

辞書ショートカット

すべての辞書の索引

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

   

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



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

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

©2025 GRAS Group, Inc.RSS