Export (0) Print
Expand All

ResourceManager.GetString Method (String)

.NET Framework 1.1

Returns the value of the specified String resource.

[Visual Basic]
Overloads Public Overridable Function GetString( _
   ByVal name As String _
) As String
[C#]
public virtual string GetString(
 string name
);
[C++]
public: virtual String* GetString(
 String* name
);
[JScript]
public function GetString(
   name : String
) : String;

Parameters

name
The name of the resource to get.

Return Value

The value of the resource localized for the caller's current culture settings. If a match is not possible, a null reference (Nothing in Visual Basic) is returned.

Exceptions

Exception Type Condition
ArgumentNullException The name parameter is a null reference (Nothing in Visual Basic).
InvalidOperationException The value of the specified resource is not a string.
MissingManifestResourceException No usable set of resources has been found, and there are no neutral culture resources.

Remarks

The resource that is returned is localized for the culture determined by the cultural settings of the current Thread (this is accomplished using the culture's CurrentUICulture property). If the resource has not been localized for that culture, the resource that is returned is localized for a best match (this is accomplished using the Parent property). Otherwise, a null reference (Nothing in Visual Basic) is returned.

If no usable set of resources has been found, the ResourceManager falls back on the neutral culture's resources, which are expected to be in the main assembly. If an appropriate culture resource has not been found, a MissingManifestResourceException is thrown.

Note   The GetString method is thread-safe.

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())      
           
        ' Retrieve the value of the string resource named "welcome".
        ' The resource manager will retrieve the value of the  
        ' localized resource using the caller's current culture setting.
        Dim str As String = rm.GetString("welcome")
         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());

        
        // Retrieve the value of the string resource named "welcome".
        // The resource manager will retrieve the value of the  
        // localized resource using the caller's current culture setting.
        String str = rm.GetString("welcome");
        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());


    // Retrieve the value of the string resource named S"welcome".
    // The resource manager will retrieve the value of the
    // localized resource using the caller's current culture setting.
    String*  str = rm->GetString(S"welcome");
    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

.NET Framework Security: 

See Also

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

Show:
© 2014 Microsoft