ResourceManager.GetString Method (String)
Microsoft Silverlight will reach end of support after October 2021. Learn more.
Returns the value of the specified String resource.
Namespace: System.Resources
Assembly: mscorlib (in mscorlib.dll)
Syntax
'Declaration
Public Overridable Function GetString ( _
name As String _
) As String
public virtual string GetString(
string name
)
Parameters
- name
Type: System.String
The name of the resource to get.
Return Value
Type: System.String
The value of the resource localized for the caller's current culture settings. If a match is not possible, nulla null reference (Nothing in Visual Basic) is returned.
Exceptions
Exception | Condition |
---|---|
ArgumentNullException | The name parameter is nulla 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, nulla 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.
For more information about how resources are found, see Localizing Silverlight-based Applications.
Note: |
---|
The GetString method is thread-safe. |
Caution: |
---|
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. |
Examples
The following code example gets a string resource using the current UI culture.
Imports System.Globalization
Imports System.Threading
Imports System.Resources
Imports System.Reflection
Class Example
Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
' 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")
outputBlock.Text &= str & vbCrLf
End Sub
End Class
using System;
using System.Globalization;
using System.Threading;
using System.Resources;
using System.Reflection;
class Example
{
public static void Demo(System.Windows.Controls.TextBlock outputBlock)
{
// 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");
outputBlock.Text += str + "\n";
}
}
Version Information
Silverlight
Supported in: 5, 4, 3
Silverlight for Windows Phone
Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0
XNA Framework
Supported in: Xbox 360, Windows Phone OS 7.0
Platforms
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.