ResourceReader.GetEnumerator 메서드

정의

ResourceReader 개체에 대한 열거자를 반환합니다.

public:
 virtual System::Collections::IDictionaryEnumerator ^ GetEnumerator();
public:
 System::Collections::IDictionaryEnumerator ^ GetEnumerator();
public System.Collections.IDictionaryEnumerator GetEnumerator ();
abstract member GetEnumerator : unit -> System.Collections.IDictionaryEnumerator
override this.GetEnumerator : unit -> System.Collections.IDictionaryEnumerator
member this.GetEnumerator : unit -> System.Collections.IDictionaryEnumerator
Public Function GetEnumerator () As IDictionaryEnumerator

반환

IDictionaryEnumerator

ResourceReader 개체에 대한 열거자입니다.

구현

예외

판독기가 닫혔거나 삭제되었으므로 액세스할 수 없는 경우

예제

이 섹션의 예제에서는 명명 된.txt 파일 PatientForm.txt 애플리케이션에서 사용 하는 리소스를 정의 합니다.

Title="Top Pet Animal Clinic"  
Label1="Patient Number:"  
Label2="Pet Name:"  
Label3="Species:"  
Label4="Breed:"  
Label5="Date of Birth:"  
Label6="Age:"  
Label7="Owner:"  
Label8="Address:"  
Label9="Home Phone:"  
Label10="Work Phone:"  
Label11="Mobile Phone:"  

다음 명령을 실행하여 .txt 파일을 .resources 파일로 컴파일할 수 있습니다.

resgen PatientForm.txt

다음 예제에서는 리소스를 열거하고 각 리소스 PatientForm.resources 의 이름과 값을 표시합니다.

using System;
using System.Collections;
using System.Resources;

public class Example
{
   public static void Main()
   {
      var rr = new ResourceReader("PatientForm.resources");
      IDictionaryEnumerator dict = rr.GetEnumerator();
      int ctr = 0;

      while (dict.MoveNext()) {
         ctr++;
         Console.WriteLine("{0:00}: {1} = {2}", ctr, dict.Key, dict.Value);
      }

      rr.Close();
   }
}
// The example displays the following output:
//       01: Label3 = "Species:"
//       02: Label2 = "Pet Name:"
//       03: Label1 = "Patient Number:"
//       04: Label7 = "Owner:"
//       05: Label6 = "Age:"
//       06: Label5 = "Date of Birth:"
//       07: Label4 = "Breed:"
//       08: Label9 = "Home Phone:"
//       09: Label8 = "Address:"
//       10: Title = "Top Pet Animal Clinic"
//       11: Label10 = "Work Phone:"
//       12: Label11 = "Mobile Phone:"
Imports System.Collections
Imports System.Resources

Module Example
   Public Sub Main()
      Dim rr As New ResourceReader("PatientForm.resources")
      Dim dict As IDictionaryEnumerator = rr.GetEnumerator
      Dim ctr As Integer

      Do While dict.MoveNext()
         ctr += 1
         Console.WriteLine("{0:00}: {1} = {2}", ctr, dict.Key, dict.Value)
      Loop
      
      rr.Close()
   End Sub
End Module
' The example displays the following output:
'       01: Label3 = "Species:"
'       02: Label2 = "Pet Name:"
'       03: Label1 = "Patient Number:"
'       04: Label7 = "Owner:"
'       05: Label6 = "Age:"
'       06: Label5 = "Date of Birth:"
'       07: Label4 = "Breed:"
'       08: Label9 = "Home Phone:"
'       09: Label8 = "Address:"
'       10: Title = "Top Pet Animal Clinic"
'       11: Label10 = "Work Phone:"
'       12: Label11 = "Mobile Phone:"

설명

일반적으로 메서드를 호출 GetEnumerator 한 다음 메서드가 반환false될 때까지 반환 IDictionaryEnumerator 된 개체에서 메서드를 반복적으로 호출 MoveNext 하여 리소스를 열거합니다. 리소스 이름은 속성에서 IDictionaryEnumerator.Key 사용할 수 있으며 속성의 값입니다 IDictionaryEnumerator.Value . 이 예제에서는 이러한 방식으로 리소스를 열거하는 방법을 보여 줍니다.

클래스에 의한 IDictionaryEnumerator.Value 속성 구현은 ResourceReader 다음 예외를 throw할 수 있습니다.

메서드를 호출 GetResourceData 하여 명명된 리소스에 할당된 데이터 형식 및 바이트 배열에 대한 정보를 검색하여 예외를 처리할 수 있습니다. 자세한 내용은 클래스 항목의 "GetResourceData를 사용하여 이름으로 리소스 검색" 섹션을 ResourceReader 참조하세요.

중요

클래스에는 ResourceReader 열거자를 반환하는 두 가지 메서드가 포함됩니다. 이 메서드는 GetEnumerator 인터페이스 개체를 IDictionaryEnumerator 반환하며 리소스를 열거할 때 호출하는 데 권장되는 방법입니다.

적용 대상

추가 정보