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.
System.Object
System.Resources.ResourceReader
[Visual Basic] NotInheritable Public Class ResourceReader Implements IResourceReader, IEnumerable, IDisposable [C#] public sealed class ResourceReader : IResourceReader, IEnumerable, IDisposable [C++] public __gc __sealed class ResourceReader : public IResourceReader, IEnumerable, IDisposable [JScript] 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.
Remarks
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.
Example
[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() Console.WriteLine("Name: {0}", en.Key) Console.WriteLine("Value: {0}", en.Value) End While reader.Close() End Sub End Class [C#] 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(); Console.WriteLine("Name: {0}", en.Key); Console.WriteLine("Value: {0}", en.Value); } reader.Close(); } } [C++] 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(); Console::WriteLine(S"Name: {0}", en->Key); Console::WriteLine(S"Value: {0}", en->Value); } reader->Close(); }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
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