ResourceManager.GetString Method (String, CultureInfo)
Returns 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
- Type: System.String
The name of the resource to retrieve.
- Type: System.Globalization.CultureInfo
An object that represents the culture for which the resource is localized.
Return ValueType: System.String
The value of the resource localized for the specified culture, or Nothing if name cannot be found in a resource set.
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. For information about how to handle this exception, see the "Handling MissingManifestResourceException and MissingSatelliteAssemblyException Exceptions" section in the ResourceManager class topic.
The default culture's resources reside in a satellite assembly that could not be found. For information about how to handle this exception, see the "Handling MissingManifestResourceException and MissingSatelliteAssemblyException Exceptions" section in the ResourceManager class topic.
If culture is Nothing, the method uses the current UI culture obtained from the CultureInfo.CurrentUICulture property.
The resource that is returned is localized for the culture specified by the culture parameter. If the resource has not been localized for culture, ResourceManager probes for a resource by following the steps outlined in the "Resource Fallback Process" section of the Packaging and Deploying Resources article. If no usable set of resources is found, the ResourceManager falls back on the neutral culture's resources, which are usually expected to be in the main assembly. If ResourceManager cannot load the neutral culture's resource set, the method throws a MissingManifestResourceException exception. If ResourceManager can load an appropriate resource set but cannot find a resource named name, the method returns Nothing.
The IgnoreCase property determines whether the comparison of name with the names of resources is case-insensitive (the default) or case-sensitive.
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 exception might be thrown if an error was made deploying or installing a satellite assembly, or a SerializationException exception might be thrown if a user-defined type throws a user-defined exception when the type is deserialized.
The following example uses the method to retrieve culture-specific resources. The example's default culture is English (en), and it includes satellite assemblies for the French (France) (fr-FR) and Russian (Russia) (ru-RU) cultures. The example changes the current culture and current UI culture to Russian (Russia) before calling . It then calls the GetString method and the DateTime.ToString(String, IFormatProvider) method and passes CultureInfo objects that represent the French (France) and Swedish (Sweden) cultures to each method. In the output, the month and day of the month as well as the string that precedes them appear in French, because the GetString method is able to retrieves the French language resource. However, when the Swedish (Sweden) culture is used, the month and day of the month appear in Swedish, although the string that precedes them is in English. This is because the resource manager cannot find localized Swedish language resources, which causes it to return a resource for the default English culture.
The example requires the text-based resource files listed in following table. Each has a single string resource named DateStart.
Aujourd'hui, c'est le
You can use the following batch file to compile the Visual Basic example. To compile in C#, change vbc to csc, and change the extension of the source code file from .vb to .cs.
resgen DateStrings.txt vbc showdate.vb /resource:DateStrings.resources md fr-FR resgen DateStrings.fr-FR.txt al /out:fr-FR\Showdate.resources.dll /culture:fr-FR /embed:DateStrings.fr-FR.resources md ru-RU resgen DateStrings.ru-RU.txt al /out:ru-RU\Showdate.resources.dll /culture:ru-RU /embed:DateStrings.ru-RU.resources
The following source code file is named ShowDate.vb or ShowDate.cs.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.