ResourceSet.GetEnumerator 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
IDictionaryEnumerator 전체에 걸쳐 반복할 수 있는 ResourceSet를 반환합니다.
public:
virtual System::Collections::IDictionaryEnumerator ^ GetEnumerator();
public virtual System.Collections.IDictionaryEnumerator GetEnumerator ();
[System.Runtime.InteropServices.ComVisible(false)]
public virtual System.Collections.IDictionaryEnumerator GetEnumerator ();
abstract member GetEnumerator : unit -> System.Collections.IDictionaryEnumerator
override this.GetEnumerator : unit -> System.Collections.IDictionaryEnumerator
[<System.Runtime.InteropServices.ComVisible(false)>]
abstract member GetEnumerator : unit -> System.Collections.IDictionaryEnumerator
override this.GetEnumerator : unit -> System.Collections.IDictionaryEnumerator
Public Overridable Function GetEnumerator () As IDictionaryEnumerator
반환
이 ResourceSet에 대한 IDictionaryEnumerator입니다.
- 특성
예외
리소스 집합이 닫혔거나 삭제된 경우
예제
다음 예제에서는 파일 items.resources
에 대 한 를 ResourceSetrs
만드는 방법을 보여 줍니다. 다음으로 메서드는 GetEnumerator 에 대한 rs
을 IDictionaryEnumerator 만드는 데 사용됩니다. 은 IDictionaryEnumerator 를 반복 rs
하고 콘솔에 콘텐츠를 표시합니다.
using namespace System;
using namespace System::Resources;
using namespace System::Collections;
int main()
{
// Create a ResourceSet for the file items.resources.
ResourceSet^ rs = gcnew ResourceSet( "items.resources" );
// Create an IDictionaryEnumerator* to read the data in the ResourceSet.
IDictionaryEnumerator^ id = rs->GetEnumerator();
// Iterate through the ResourceSet and display the contents to the console.
while ( id->MoveNext() )
Console::WriteLine( "\n [{0}] \t {1}", id->Key, id->Value );
rs->Close();
}
using System;
using System.Resources;
using System.Collections;
class EnumerateResources
{
public static void Main()
{
// Create a ResourceSet for the file items.resources.
ResourceSet rs = new ResourceSet("items.resources");
// Create an IDictionaryEnumerator to read the data in the ResourceSet.
IDictionaryEnumerator id = rs.GetEnumerator();
// Iterate through the ResourceSet and display the contents to the console.
while(id.MoveNext())
Console.WriteLine("\n[{0}] \t{1}", id.Key, id.Value);
rs.Close();
}
}
Imports System.Resources
Imports System.Collections
Class EnumerateResources
Public Shared Sub Main()
' Create a ResourceSet for the file items.resources.
Dim rs As New ResourceSet("items.resources")
' Create an IDictionaryEnumerator to read the data in the ResourceSet.
Dim id As IDictionaryEnumerator = rs.GetEnumerator()
' Iterate through the ResourceSet and display the contents to the console.
While id.MoveNext()
Console.WriteLine(ControlChars.NewLine + "[{0}] " + ControlChars.Tab + "{1}", id.Key, id.Value)
End While
rs.Close()
End Sub
End Class
설명
열거자는 컬렉션의 데이터 읽기를 허용 합니다. 내부 컬렉션을 수정 하 여 열거자를 사용할 수 없습니다.
처음에 열거자는 컬렉션의 첫 번째 요소 앞에 배치됩니다. Reset을 실행하면 열거자가 이 위치로 복원됩니다. 이 위치에서, 호출 Current 예외를 throw 합니다. 따라서 MoveNext의 값을 읽기 전에 Current를 호출하여 열거자를 해당 컬렉션의 첫 번째 요소로 보내야 합니다.
Current에서는 MoveNext 또는 Reset이 호출될 때까지 동일한 개체를 반환합니다. MoveNext는 Current를 다음 요소로 설정합니다.
컬렉션의 끝이 전달된 후 열거자는 컬렉션의 마지막 요소 뒤에 배치되고 MoveNext를 호출하면 false
가 반환됩니다. 마지막으로 호출 하는 경우 MoveNext 반환 false
호출, Current 예외를 throw 합니다. Current를 컬렉션의 첫째 요소에 다시 설정하려면 Reset을 호출한 뒤 MoveNext를 호출해야 합니다.
컬렉션이 변경되지 않고 그대로 유지되는 한 열거자는 유효한 상태로 유지됩니다. 요소를 추가, 수정 또는 삭제하는 등 컬렉션을 변경하는 경우 열거자는 무효화되고 복구할 수 없으며 MoveNext 또는 Reset을 다음에 호출할 때 InvalidOperationException이 발생합니다. MoveNext 및 Current 사이에 컬렉션이 수정되면 열거자가 이미 무효로 되었어도 Current는 컬렉션이 설정된 요소를 반환합니다.
속성을 사용하여 IDictionaryEnumerator.Entry 현재 요소에 저장된 값에 액세스할 수 있습니다. 사용 된 IDictionaryEnumerator.Key 현재 요소의 키에 액세스 하는 속성입니다. 사용 된 IDictionaryEnumerator.Value 현재 요소의 값에 액세스 하는 속성입니다.
열거자는 컬렉션에 배타적으로 액세스하지 못하므로 컬렉션을 열거하는 것은 본질적으로 스레드로부터 안전한 프로시저가 아닙니다. 컬렉션이 동기화 된 경우 다른 스레드 수 수정할 하면 열거자가 예외를 throw 하는 컬렉션입니다. 열거하는 동안 스레드로부터 안전을 보장하려면 전체 열거를 수행하는 동안 컬렉션을 잠그거나 다른 스레드에서 변경된 내용으로 인해 발생한 예외를 catch하면 됩니다.
적용 대상
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기