Thursday, November 19, 2015

In C#, how may I read from a resource by way of fishing with a magic string for the key.

If the project were called "MyResources" and we wish to read the line item for "Whatever" from "Errors.resx" both of these lines of code would be successful in doing so and their variables would match in an equality comparison.

string foo = MyResources.Errors.Whatever;
string bar = MyResources.Errors.ResourceManager.GetString("Whatever");

No comments:

Post a Comment