Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
Previous Versions
.NET Framework 1.1
.NET Framework
Reference
System.Resources
 ResourceManager Constructor (String...
.NET Framework Class Library
ResourceManager Constructor (String, Assembly)

Initializes a new instance of the ResourceManager class that looks up resources contained in files derived from the specified root name using the given Assembly.

[Visual Basic]
Public Sub New( _
   ByVal baseName As String, _
   ByVal assembly As Assembly _
)
[C#]
public ResourceManager(
   string baseName,
 Assembly assembly
);
[C++]
public: ResourceManager(
   String* baseName,
 Assembly* assembly
);
[JScript]
public function ResourceManager(
   baseName : String,
 assembly : Assembly
);

Parameters

baseName
The root name of the resources. For example, the root name for the resource file named "MyResource.en-US.resources" is "MyResource".
assembly
The main Assembly for the resources.

Exceptions

Exception Type Condition
ArgumentNullException The baseName or assembly parameter is a null reference (Nothing in Visual Basic).

Remarks

The individual resource files should be contained in satellite assemblies with the invariant culture's .resources file contained in the main assembly. A satellite assembly is assumed to contain resources for a single culture specified in that assembly's manifest, and are loaded as necessary.

This constructor uses the system provided ResourceSet implementation. To use a custom resource file format, you should derive from the ResourceSet class, override GetDefaultReader and GetDefaultWriter, and pass that type to the constructor that takes a Type as the third parameter. Using a custom ResourceSet can be useful for controlling resource caching policy or supporting your own resource file format, but is generally not necessary.

Example

[Visual Basic] 
Imports System
Imports System.Globalization
Imports System.Threading
Imports System.Resources
Imports System.Reflection

Class ResourcesExample
   
    Public Shared Sub Main()
        ' Create a resource manager to retrieve resources.
        Dim rm As New ResourceManager("items", _
           [Assembly].GetExecutingAssembly())
       
        ' Get the culture of the currently executing thread.
        ' The value of ci will determine the culture of
        ' the resources that the resource manager retrieves.
        Dim ci As CultureInfo = Thread.CurrentThread.CurrentCulture
      
        ' Retrieve the value of the string resource named 
        ' "welcome" localized for the culture specified by ci.
        Dim str As [String] = rm.GetString("welcome", ci)
        Console.WriteLine(str)
    End Sub
End Class

[C#] 
using System;
using System.Globalization;
using System.Threading;
using System.Resources;
using System.Reflection;

class ResourcesExample 
{
    public static void Main() 
    {
       // Create a resource manager to retrieve resources.
       ResourceManager rm = new ResourceManager("items", 
          Assembly.GetExecutingAssembly());

       // Get the culture of the currently executing thread.
       // The value of ci will determine the culture of
       // the resources that the resource manager retrieves.
       CultureInfo ci = Thread.CurrentThread.CurrentCulture;
        
       // Retrieve the value of the string resource named 
       // "welcome", localized for the culture specified by ci.
       String str = rm.GetString("welcome", ci);
       Console.WriteLine(str);
    }
}

[C++] 
#using <mscorlib.dll>

using namespace System;
using namespace System::Globalization;
using namespace System::Threading;
using namespace System::Resources;
using namespace System::Reflection;

int main() {
    // Create a resource manager to retrieve resources.
    ResourceManager* rm = new ResourceManager(S"items",
        Assembly::GetExecutingAssembly());

    // Get the culture of the currently executing thread.
    // The value of ci will determine the culture of
    // the resources that the resource manager retrieves.
    CultureInfo*  ci = Thread::CurrentThread->CurrentCulture;

    // Retrieve the value of the string resource named
    // S"welcome", localized for the culture specified by ci.
    String*  str = rm->GetString(S"welcome", ci);
    Console::WriteLine(str);
}

[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, .NET Compact Framework

See Also

ResourceManager Class | ResourceManager Members | System.Resources Namespace | ResourceManager Constructor Overload List

© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker