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

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
 
T

Tom Clement

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top