How to use the "Resource Assembly File (*.resx)"?

  • Thread starter Thread starter gg
  • Start date Start date
G

gg

Hello, who can tell me how to use the Resource Assembly File (*.resx) in a
project. For example:
I define a item Name :"TestString" Vale "1234567890" in a Resource Assembly
File(test.resx).
How to load the string vale?

Thanks
 
You could do something like this:

public sealed class MyStrings
{
private static ResourceManager ms_oRM = new
ResourceManager(typeof(MyStrings));
private AppteroStrings {}
public static string GetString(string stringID)
{
string s = ms_oRM.GetString(name);
if( s == null )
throw new
MissingManifestResourceException(string.Format(CultureInfo.CurrentUICulture,
"Could not find string for ID {0}", stringID));
return s;
}
}

This assumes that you have created a resource file called MyStrings.resx.
The static access means you only have to create the resource manager once.
Tom Clement
Apptero, Inc.
 
Back
Top