ResourceReader.GetEnumerator Metodo

Definizione

Restituisce un enumeratore per questo oggetto 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

Restituisce

Enumeratore per questo oggetto ResourceReader.

Implementazioni

Eccezioni

Il lettore è stato chiuso o eliminato e non è possibile accedervi.

Esempio

Nell'esempio riportato in questa sezione viene usato il file di .txt seguente denominato PatientForm.txt per definire le risorse usate da un'applicazione.

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:"

È possibile compilare il file .txt in un file con estensione resources eseguendo il comando seguente:

resgen PatientForm.txt

Nell'esempio seguente vengono enumerate le risorse in PatientForm.resources e viene visualizzato il nome e il valore di ognuno di essi.

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:"

Commenti

In genere, le risorse vengono enumerate chiamando il GetEnumerator metodo e quindi chiamando ripetutamente il MoveNext metodo sull'oggetto restituito IDictionaryEnumerator fino a quando il metodo non restituisce false. Il nome della risorsa è disponibile dalla IDictionaryEnumerator.Key proprietà; il relativo valore dalla IDictionaryEnumerator.Value proprietà . Nell'esempio viene illustrato come enumerare le risorse in questo modo.

L'implementazione della IDictionaryEnumerator.Value proprietà dalla ResourceReader classe può generare le eccezioni seguenti:

È possibile gestire l'eccezione chiamando il GetResourceData metodo per recuperare informazioni sul tipo di dati e sulla matrice di byte assegnata alla risorsa denominata. Per altre informazioni, vedere la sezione "Recupero delle risorse per nome con GetResourceData" nell'argomento della ResourceReader classe.

Importante

La ResourceReader classe include due metodi che restituiscono enumeratori. Il GetEnumerator metodo restituisce un IDictionaryEnumerator oggetto interfaccia ed è il metodo consigliato da chiamare durante l'enumerazione delle risorse.

Si applica a

Vedi anche