ArrayList 클래스의 Item 속성을 사용하여 ArrayList의 지정된 인덱스에 있는 요소를 가져오거나 설정합니다.
Item 속성은 인덱서이므로 속성 이름을 추가하지 않고도 사용할 수 있습니다.
아래 예에서는 다음과 같이 사용했습니다 -
Console.WriteLine("Element {0} is \"{1}\"", 2, arrList[1]); Item 속성을 사용하는 방법을 배우기 위해 전체 예제를 살펴보겠습니다.
예시
using System;
using System.Collections;
class Demo {
public static void Main() {
ArrayList arrList = new ArrayList();
arrList.Add(45);
arrList.Add(78);
arrList.Add(88);
Console.WriteLine("Total elements: "+arrList.Count);
Console.WriteLine("Element {0} is \"{1}\"", 2, arrList[1]);
}
} 출력
Total elements: 3 Element 2 is "78"