GetString Method (String, CultureInfo)
Collapse the table of content
Expand the table of content

ResourceManager.GetString Method (String, CultureInfo)

Gets the value of the String resource localized for the specified culture.

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

'Declaration
Public Overridable Function GetString ( _
	name As String, _
	culture As CultureInfo _
) As String
'Usage
Dim instance As ResourceManager
Dim name As String
Dim culture As CultureInfo
Dim returnValue As String

returnValue = instance.GetString(name, culture)
public String GetString (
	String name, 
	CultureInfo culture
)
public function GetString (
	name : String, 
	culture : CultureInfo
) : String

Parameters

name

The name of the resource to get.

culture

The CultureInfo object that represents the culture for which the resource is localized. Note that if the resource is not localized for this culture, the lookup will fall back using the culture's Parent property, stopping after looking in the neutral culture.

If this value is a null reference (Nothing in Visual Basic), the CultureInfo is obtained using the culture's CurrentUICulture property.

Return Value

The value of the resource localized for the specified culture. If a best 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.

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 culture's 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.

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

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

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

        // 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 = 
            System.Threading.Thread.get_CurrentThread().get_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);
    } //main
} //ResourcesExample

Windows 98, Windows 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 .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2016 Microsoft