Export (0) Print
Expand All

ResXResourceReader.GetEnumerator Method

Returns an enumerator for this ResXResourceReader.

[Visual Basic]
Public Overridable Function GetEnumerator() As IDictionaryEnumerator _
   Implements IResourceReader.GetEnumerator
[C#]
public virtual IDictionaryEnumerator GetEnumerator();
[C++]
public: virtual IDictionaryEnumerator* GetEnumerator();
[JScript]
public function GetEnumerator() : IDictionaryEnumerator;

Return Value

An IDictionaryEnumerator for this ResourceReader.

Implements

IResourceReader.GetEnumerator

Remarks

The GetEnumerator method steps though the name/value pairs stored in the XML resource (.resx) file.

Example

[Visual Basic] 
Imports System
Imports System.Resources
Imports System.Collections
Imports Microsoft.VisualBasic

Class ReadResXResources
   
   Public Shared Sub Main()
      
      ' Create a ResXResourceReader for the file items.resx.
      Dim rsxr As ResXResourceReader
      rsxr = New ResXResourceReader("items.resx")

      ' Create an IDictionaryEnumerator to iterate through the resources.
      Dim id As IDictionaryEnumerator = rsxr.GetEnumerator()
            
      ' Iterate through the resources and display the contents to the console.
      Dim d As DictionaryEntry
      For Each d In  rsxr
         Console.WriteLine(d.Key.ToString() + ":" + ControlChars.Tab + d.Value.ToString())
      Next d
      
      'Close the reader.
      rsxr.Close()

   End Sub

End Class

[C#] 
using System;
using System.Resources;
using System.Collections;

class ReadResXResources
{
   public static void Main()
   {
   
      // Create a ResXResourceReader for the file items.resx.
      ResXResourceReader rsxr = new ResXResourceReader("items.resx");

      // Create an IDictionaryEnumerator to iterate through the resources.
      IDictionaryEnumerator id = rsxr.GetEnumerator();       

      // Iterate through the resources and display the contents to the console.
      foreach (DictionaryEntry d in rsxr) 
      {
    Console.WriteLine(d.Key.ToString() + ":\t" + d.Value.ToString());
      }

     //Close the reader.
     rsxr.Close();
   }
}

[C++] 
#using <mscorlib.dll>
#using <system.windows.forms.dll>

using namespace System;
using namespace System::Resources;
using namespace System::Collections;

void main()
{
   // Create a ResXResourceReader for the file items.resx.
   ResXResourceReader* rsxr = new ResXResourceReader(S"items.resx");

   // Create an IDictionaryEnumerator* to iterate through the resources.
   IDictionaryEnumerator* id = rsxr->GetEnumerator();       

   // Iterate through the resources and display the contents to the console.
   IEnumerator* myEnum = rsxr->GetEnumerator();
   while (myEnum->MoveNext())
   {
      DictionaryEntry* d = __try_cast<DictionaryEntry*>(myEnum->Current);

      Console::WriteLine(S"{0}:\t {1}", d->Key, d->Value);
   }

   //Close the reader.
   rsxr->Close();
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

ResXResourceReader Class | ResXResourceReader Members | System.Resources Namespace

Show:
© 2014 Microsoft