ArrayList.Item プロパティ
アセンブリ: mscorlib (mscorlib.dll 内)

Dim instance As ArrayList Dim index As Integer Dim value As Object value = instance(index) instance(index) = value
public: virtual property Object^ default [int] { Object^ get (int index); void set (int index, Object^ value); }
/** @property */ public Object get_Item (int index) /** @property */ public void set_Item (int index, Object value)
プロパティ値
指定したインデックスにある要素。


ArrayList は、null 参照 (Visual Basic では Nothing) を有効な値として受け取り、要素の重複を許可します。
このプロパティでは、myCollection[index] という構文を使用して、コレクション内の特定の要素にアクセスできます。
このプロパティ値を取得することは、O(1) 操作になります。また、このプロパティを設定することも O(1) 操作になります。

ArrayList を作成し、いくつかの項目を追加するコード例を次に示します。この例では、Item プロパティ (C# の場合はインデクサ) によって要素にアクセスし、指定されたインデックスに対して新しい値を Item プロパティに割り当てることによって要素を変更しています。また、Item プロパティを使って、リストの現在のサイズを越えて要素にアクセスしたり、要素を追加したりできないことも示しています。
Imports System Imports System.Collections Imports Microsoft.VisualBasic Public Class Example Public Shared Sub Main ' Create an empty ArrayList, and add some elements. Dim stringList As New ArrayList stringList.Add("a") stringList.Add("abc") stringList.Add("abcdef") stringList.Add("abcdefg") ' Item is the default property, so the property name is ' not required. Console.WriteLine("Element {0} is ""{1}""", 2, stringList(2)) ' Assigning a value to the property changes the value of ' the indexed element. stringList(2) = "abcd" Console.WriteLine("Element {0} is ""{1}""", 2, stringList(2)) ' Accessing an element outside the current element count ' causes an exception. The ArrayList index is zero-based, ' so the index of the last element is (Count - 1). Console.WriteLine("Number of elements in the list: {0}", _ stringList.Count) Try Console.WriteLine("Element {0} is ""{1}""", _ stringList.Count, _ stringList(stringList.Count)) Catch aoore As ArgumentOutOfRangeException Console.WriteLine("stringList({0}) is out of range.", _ stringList.Count) End Try ' You cannot use the Item property to add new elements. Try stringList(stringList.Count) = "42" Catch aoore As ArgumentOutOfRangeException Console.WriteLine("stringList({0}) is out of range.", _ stringList.Count) End Try Console.WriteLine() For i As Integer = 0 To stringList.Count - 1 Console.WriteLine("Element {0} is ""{1}""", i, stringList(i)) Next Console.WriteLine() For Each o As Object In stringList Console.WriteLine(o) Next End Sub End Class ' ' This code example produces the following output: ' 'Element 2 is "abcdef" 'Element 2 is "abcd" 'Number of elements in the list: 4 'stringList(4) is out of range. 'stringList(4) is out of range. ' 'Element 0 is "a" 'Element 1 is "abc" 'Element 2 is "abcd" 'Element 3 is "abcdefg" ' 'a 'abc 'abcd 'abcdefg
using System; using System.Collections; public class Example { public static void Main() { // Create an empty ArrayList, and add some elements. ArrayList stringList = new ArrayList(); stringList.Add("a"); stringList.Add("abc"); stringList.Add("abcdef"); stringList.Add("abcdefg"); // The Item property is an indexer, so the property name is // not required. Console.WriteLine("Element {0} is \"{1}\"", 2, stringList[2]); // Assigning a value to the property changes the value of // the indexed element. stringList[2] = "abcd"; Console.WriteLine("Element {0} is \"{1}\"", 2, stringList[2]); // Accessing an element outside the current element count // causes an exception. Console.WriteLine("Number of elements in the list: {0}", stringList.Count); try { Console.WriteLine("Element {0} is \"{1}\"", stringList.Count, stringList[stringList.Count]); } catch(ArgumentOutOfRangeException aoore) { Console.WriteLine("stringList({0}) is out of range.", stringList.Count); } // You cannot use the Item property to add new elements. try { stringList[stringList.Count] = "42"; } catch(ArgumentOutOfRangeException aoore) { Console.WriteLine("stringList({0}) is out of range.", stringList.Count); } Console.WriteLine(); for (int i = 0; i < stringList.Count; i++) { Console.WriteLine("Element {0} is \"{1}\"", i, stringList[i]); } Console.WriteLine(); foreach (object o in stringList) { Console.WriteLine(o); } } } /* This code example produces the following output: Element 2 is "abcdef" Element 2 is "abcd" Number of elements in the list: 4 stringList(4) is out of range. stringList(4) is out of range. Element 0 is "a" Element 1 is "abc" Element 2 is "abcd" Element 3 is "abcdefg" a abc abcd abcdefg */

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からArrayList.Item プロパティを検索する場合は、下記のリンクをクリックしてください。

- ArrayList.Item プロパティのページへのリンク