ResourceManager.GetString Method (String, CultureInfo)
Updated: May 2012
Gets the value of the String resource localized for the specified culture.
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)
- Type: System.String
The name of the resource to get.
- Type: System.Globalization.CultureInfo
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 current thread's Parent property, stopping after looking in the neutral culture.
Return ValueType: System.String
The value of the resource localized for the specified culture. If a best match is not possible, Nothing is returned.
The name parameter is Nothing.
The value of the specified resource is not a String.
No usable set of resources has been found, and there are no neutral culture resources.
The default culture's resources reside in a satellite assembly that could not be found.
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 current thread's Parent property). Otherwise, Nothing 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.
The GetString method is thread-safe.
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 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
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.