Export (0) Print
Expand All

ResourceManager.GetString Method (String)

Returns the value of the specified String resource.

Namespace: System.Resources
Assembly: mscorlib (in mscorlib.dll)

public virtual string GetString (
	string name
)
public String GetString (
	String name
)
public function GetString (
	name : String
) : String
Not applicable.

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.

Exception typeCondition

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.

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.

NoteNote:

The GetString method is thread-safe.

Caution noteCaution:

This method can throw more exceptions than are listed. One reason this might occur is if a method that this method calls throws an exception. For example, a FileLoadException might be thrown if an error was made deploying or installing a satellite assembly, or a SerializationException might be thrown if a user-defined type throws a user-defined exception when the type is deserialized.

The following code example gets a string resource using the current UI culture.

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);
    }
}

import System.*;
import System.Globalization.*;
import System.Threading.*;
import System.Resources.*;
import System.Reflection.*;

class ResourcesExample
{

    public static void main(String[] args)
    {
        // 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);
    } //main
} //ResourcesExample

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0

Community Additions

ADD
Show:
© 2014 Microsoft