Search code examples
c#performanceresourcesassembliesresx

C# - Fastest way to get resource string from assembly


I really don't know/have the answer, knowledge to find a resource value using a key from a resx file in a assembly using c#.(or may be i am ignorant).

What would be the fastest code, way i can retrieve string values or values using a key from a resource file which is embedded as resource in a assembly. I am storing friendly messages for exceptions in the resource file and would like to use them when required.

Does a static class exist for this purpose?

Are there open source mature projects i can use for this?


Solution

  • Assembly assembly = this.GetType().Assembly;
    ResourceManager resourceManager = new ResourceManager("Resources.Strings", assembly);
    string myString = resourceManager.GetString("value");