Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

ResourceReader Class

Enumerates .resources files and streams, reading sequential resource name and value pairs.

For a list of all members of this type, see ResourceReader Members.


[Visual Basic]
NotInheritable Public Class ResourceReader
   Implements IResourceReader, IEnumerable, IDisposable
public sealed class ResourceReader : IResourceReader, IEnumerable,
public __gc __sealed class ResourceReader : public IResourceReader,
   IEnumerable, IDisposable
public class ResourceReader implements IResourceReader,
   IEnumerable, IDisposable

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.


The ResourceReader provides a default implementation of the IResourceReader interface.

You can use resource readers to read resource name and resource value pairs from .resources files. The resources can be enumerated by traversing the IDictionaryEnumerator returned by the GetEnumerator method. The methods provided by the IDictionaryEnumerator are used to advance to the next resource and read the name and value of each resource in the .resources file.

Note    IEnumerable.GetEnumerator returns an IEnumerator not IDictionaryEnumerator.


[Visual Basic, C#, C++] The following code sample displays the content of "myResources.resources" files on the console:

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

Public Class ReadResources
    Public Shared Sub Main()
        ' Opens a resource reader and get an enumerator from it.
        Dim reader As New ResourceReader("myResources.resources")
        Dim en As IDictionaryEnumerator = reader.GetEnumerator()
        ' Goes through the enumerator, printing out the key and value pairs.
        While en.MoveNext()
            Console.WriteLine("Name: {0}", en.Key)
            Console.WriteLine("Value: {0}", en.Value)
        End While
    End Sub
End Class

using System;
using System.Resources;
using System.Collections;
public class ReadResources {

   public static void Main(string[] args) {

      // Opens a resource reader and gets an enumerator from it.
      IResourceReader reader = new ResourceReader("myResources.resources");
      IDictionaryEnumerator en = reader.GetEnumerator();
      // Goes through the enumerator, printing out the key and value pairs.
      while (en.MoveNext()) {
         Console.WriteLine("Name: {0}", en.Key);
         Console.WriteLine("Value: {0}", en.Value);

using namespace System;
using namespace System::Resources;
using namespace System::Collections;
int main() {

      // Opens a resource reader and gets an enumerator from it.
      IResourceReader* reader = new ResourceReader(S"myResources.resources");
      IDictionaryEnumerator* en = reader->GetEnumerator();
      // Goes through the enumerator, printing out the key and value pairs.
      while (en->MoveNext()) {
          Console::WriteLine(S"Name: {0}", en->Key);
          Console::WriteLine(S"Value: {0}", en->Value);

[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.


Namespace: System.Resources

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

Assembly: Mscorlib (in Mscorlib.dll)

See Also

ResourceReader Members | System.Resources Namespace | Developing World-Ready Applications | IResourceReader

© 2018 Microsoft