ResourceSet.GetEnumerator 메서드

정의

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 에 대한 rsIDictionaryEnumerator 만드는 데 사용됩니다. 은 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이 호출될 때까지 동일한 개체를 반환합니다. MoveNextCurrent를 다음 요소로 설정합니다.

컬렉션의 끝이 전달된 후 열거자는 컬렉션의 마지막 요소 뒤에 배치되고 MoveNext를 호출하면 false가 반환됩니다. 마지막으로 호출 하는 경우 MoveNext 반환 false호출, Current 예외를 throw 합니다. Current를 컬렉션의 첫째 요소에 다시 설정하려면 Reset을 호출한 뒤 MoveNext를 호출해야 합니다.

컬렉션이 변경되지 않고 그대로 유지되는 한 열거자는 유효한 상태로 유지됩니다. 요소를 추가, 수정 또는 삭제하는 등 컬렉션을 변경하는 경우 열거자는 무효화되고 복구할 수 없으며 MoveNext 또는 Reset을 다음에 호출할 때 InvalidOperationException이 발생합니다. MoveNextCurrent 사이에 컬렉션이 수정되면 열거자가 이미 무효로 되었어도 Current는 컬렉션이 설정된 요소를 반환합니다.

속성을 사용하여 IDictionaryEnumerator.Entry 현재 요소에 저장된 값에 액세스할 수 있습니다. 사용 된 IDictionaryEnumerator.Key 현재 요소의 키에 액세스 하는 속성입니다. 사용 된 IDictionaryEnumerator.Value 현재 요소의 값에 액세스 하는 속성입니다.

열거자는 컬렉션에 배타적으로 액세스하지 못하므로 컬렉션을 열거하는 것은 본질적으로 스레드로부터 안전한 프로시저가 아닙니다. 컬렉션이 동기화 된 경우 다른 스레드 수 수정할 하면 열거자가 예외를 throw 하는 컬렉션입니다. 열거하는 동안 스레드로부터 안전을 보장하려면 전체 열거를 수행하는 동안 컬렉션을 잠그거나 다른 스레드에서 변경된 내용으로 인해 발생한 예외를 catch하면 됩니다.

적용 대상