ArrayList.GetEnumerator 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
를 반복하는 열거자를 반환합니다 ArrayList.
오버로드
| Name | Description |
|---|---|
| GetEnumerator() |
전체 ArrayList대한 열거자를 반환합니다. |
| GetEnumerator(Int32, Int32) |
의 요소 범위에 대한 열거자를 반환합니다 ArrayList. |
GetEnumerator()
전체 ArrayList대한 열거자를 반환합니다.
public:
virtual System::Collections::IEnumerator ^ GetEnumerator();
public virtual System.Collections.IEnumerator GetEnumerator();
abstract member GetEnumerator : unit -> System.Collections.IEnumerator
override this.GetEnumerator : unit -> System.Collections.IEnumerator
Public Overridable Function GetEnumerator () As IEnumerator
반품
IEnumerator 전체 ArrayList.
구현
예제
다음 예제에서는 에 있는 요소 ArrayList범위에 대한 ArrayList열거자 및 열거자를 가져옵니다.
using System;
using System.Collections;
class Program
{
static void Main(string[] args)
{
ArrayList colors = new ArrayList();
colors.Add("red");
colors.Add("blue");
colors.Add("green");
colors.Add("yellow");
colors.Add("beige");
colors.Add("brown");
colors.Add("magenta");
colors.Add("purple");
IEnumerator e = colors.GetEnumerator();
while (e.MoveNext())
{
Object obj = e.Current;
Console.WriteLine(obj);
}
Console.WriteLine();
IEnumerator e2 = colors.GetEnumerator(2, 4);
while (e2.MoveNext())
{
Object obj = e2.Current;
Console.WriteLine(obj);
}
}
}
/* This code example produces
the following ouput:
red
blue
green
yellow
beige
brown
magenta
purple
green
yellow
beige
brown
*/
Imports System.Collections
Class Program
Private Shared Sub Main(ByVal args As String())
Dim colors As New ArrayList()
colors.Add("red")
colors.Add("blue")
colors.Add("green")
colors.Add("yellow")
colors.Add("beige")
colors.Add("brown")
colors.Add("magenta")
colors.Add("purple")
Dim e As IEnumerator = colors.GetEnumerator()
While e.MoveNext()
Dim obj As [Object] = e.Current
Console.WriteLine(obj)
End While
Console.WriteLine()
Dim e2 As IEnumerator = colors.GetEnumerator(2, 4)
While e2.MoveNext()
Dim obj As [Object] = e2.Current
Console.WriteLine(obj)
End While
End Sub
End Class
' This code example produces
' the following ouput:
' red
' blue
' green
' yellow
' beige
' brown
' magenta
' purple
'
' green
' yellow
' beige
' brown
'
설명
C# 언어의 foreach 문(Visual Basic for each)은 열거자의 복잡성을 숨깁니다. 따라서 열거자를 직접 조작하는 대신 사용하는 foreach 것이 좋습니다.
열거자는 컬렉션의 데이터를 읽는 데 사용할 수 있지만 기본 컬렉션을 수정하는 데 사용할 수는 없습니다.
처음에는 열거자가 컬렉션의 첫 번째 요소 앞에 배치됩니다. Reset 또한 열거자를 이 위치로 다시 가져옵니다. 이 위치에서 Current 정의되지 않습니다. 따라서 값을 MoveNext읽기 전에 열거자를 컬렉션의 첫 번째 요소로 이동하도록 호출 Current 해야 합니다.
Current 는 호출될 때까지 동일한 개체를 MoveNextReset 반환합니다. MoveNext 는 다음 요소로 설정 Current 됩니다.
컬렉션의 끝을 전달하면 MoveNext 열거자가 컬렉션의 마지막 요소 뒤 위치에 배치되고 MoveNext 반환됩니다 false. 열거자가 이 위치에 있으면 후속 호출도 반환MoveNext합니다false. 반환 MoveNextfalse 된 Current 마지막 호출이 정의되지 않은 경우 컬렉션의 첫 번째 요소로 다시 설정 Current 하려면 다음Reset을 호출 MoveNext 할 수 있습니다.
컬렉션이 변경되지 않은 상태로 유지되는 한 열거자는 유효한 상태로 유지됩니다. 요소 추가, 수정 또는 삭제와 같이 컬렉션이 변경되면 열거자가 복구할 수 없게 무효화되고 해당 동작이 정의되지 않습니다.
열거자는 컬렉션에 대한 단독 액세스 권한이 없습니다. 따라서 컬렉션을 열거하는 것은 본질적으로 스레드로부터 안전한 프로시저가 아닙니다. 열거 중 스레드 안전을 보장하기 위해 전체 열거형 중에 컬렉션을 잠글 수 있습니다. 읽기 및 쓰기를 위해 여러 스레드에서 컬렉션에 액세스할 수 있도록 하려면 고유한 동기화를 구현해야 합니다.
이 메서드는 작업입니다 O(1) .
추가 정보
적용 대상
GetEnumerator(Int32, Int32)
의 요소 범위에 대한 열거자를 반환합니다 ArrayList.
public:
virtual System::Collections::IEnumerator ^ GetEnumerator(int index, int count);
public virtual System.Collections.IEnumerator GetEnumerator(int index, int count);
abstract member GetEnumerator : int * int -> System.Collections.IEnumerator
override this.GetEnumerator : int * int -> System.Collections.IEnumerator
Public Overridable Function GetEnumerator (index As Integer, count As Integer) As IEnumerator
매개 변수
반품
IEnumerator 에 있는 지정된 요소 범위의 경우 ArrayList
예외
index 에 count 유효한 범위를 ArrayList지정하지 마세요.
예제
다음 예제에서는 에 있는 요소 ArrayList범위에 대한 ArrayList열거자 및 열거자를 가져옵니다.
using System;
using System.Collections;
class Program
{
static void Main(string[] args)
{
ArrayList colors = new ArrayList();
colors.Add("red");
colors.Add("blue");
colors.Add("green");
colors.Add("yellow");
colors.Add("beige");
colors.Add("brown");
colors.Add("magenta");
colors.Add("purple");
IEnumerator e = colors.GetEnumerator();
while (e.MoveNext())
{
Object obj = e.Current;
Console.WriteLine(obj);
}
Console.WriteLine();
IEnumerator e2 = colors.GetEnumerator(2, 4);
while (e2.MoveNext())
{
Object obj = e2.Current;
Console.WriteLine(obj);
}
}
}
/* This code example produces
the following ouput:
red
blue
green
yellow
beige
brown
magenta
purple
green
yellow
beige
brown
*/
Imports System.Collections
Class Program
Private Shared Sub Main(ByVal args As String())
Dim colors As New ArrayList()
colors.Add("red")
colors.Add("blue")
colors.Add("green")
colors.Add("yellow")
colors.Add("beige")
colors.Add("brown")
colors.Add("magenta")
colors.Add("purple")
Dim e As IEnumerator = colors.GetEnumerator()
While e.MoveNext()
Dim obj As [Object] = e.Current
Console.WriteLine(obj)
End While
Console.WriteLine()
Dim e2 As IEnumerator = colors.GetEnumerator(2, 4)
While e2.MoveNext()
Dim obj As [Object] = e2.Current
Console.WriteLine(obj)
End While
End Sub
End Class
' This code example produces
' the following ouput:
' red
' blue
' green
' yellow
' beige
' brown
' magenta
' purple
'
' green
' yellow
' beige
' brown
'
설명
C# 언어의 문은 foreach 열거자의 복잡성을 숨깁니다. 따라서 열거자를 직접 조작하는 대신 사용하는 foreach 것이 좋습니다.
열거자는 컬렉션의 데이터를 읽는 데 사용할 수 있지만 기본 컬렉션을 수정하는 데 사용할 수는 없습니다.
처음에는 열거자가 컬렉션의 첫 번째 요소 앞에 배치됩니다. Reset 또한 열거자를 이 위치로 다시 가져옵니다. 이 위치에서 Current 정의되지 않습니다. 따라서 값을 MoveNext읽기 전에 열거자를 컬렉션의 첫 번째 요소로 이동하도록 호출 Current 해야 합니다.
Current 는 호출될 때까지 동일한 개체를 MoveNextReset 반환합니다. MoveNext 는 다음 요소로 설정 Current 됩니다.
컬렉션의 끝을 전달하면 MoveNext 열거자가 컬렉션의 마지막 요소 뒤 위치에 배치되고 MoveNext 반환됩니다 false. 열거자가 이 위치에 있으면 후속 호출도 반환MoveNext합니다false. 반환 MoveNextfalse 된 Current 마지막 호출이 정의되지 않은 경우 컬렉션의 첫 번째 요소로 다시 설정 Current 하려면 다음Reset을 호출 MoveNext 할 수 있습니다.
컬렉션이 변경되지 않은 상태로 유지되는 한 열거자는 유효한 상태로 유지됩니다. 요소 추가, 수정 또는 삭제와 같이 컬렉션이 변경되면 열거자가 복구할 수 없게 무효화되고 해당 동작이 정의되지 않습니다.
열거자는 컬렉션에 대한 단독 액세스 권한이 없습니다. 따라서 컬렉션을 열거하는 것은 본질적으로 스레드로부터 안전한 프로시저가 아닙니다. 열거 중 스레드 안전을 보장하기 위해 전체 열거형 중에 컬렉션을 잠글 수 있습니다. 읽기 및 쓰기를 위해 여러 스레드에서 컬렉션에 액세스할 수 있도록 하려면 고유한 동기화를 구현해야 합니다.
이 메서드는 작업입니다 O(1) .