Web Developer, Software Engineer and Mixed Language Artist
RSS icon Email icon Home icon
  • Global Resource strings by property

    Posted on April 15th, 2010 Jamie No comments

    Every now and then I come across a bunch of string literals littered through out some code and begin the task of moving them out into their own resource file (.resx).

    Gaining access to these strings from C# is pretty easy however I’m yet to find anywhere explaining it the way I find simplest.

    Assuming your resx file is stored in the App_GlobalResources folder, you can basically assign your resource file to a variable in your C# using the following syntax:

    ?View Code CSHARP
    using Res = Resources.MyResourceFile

    This then gives you the ability to referene the contents of the resource file as properties in your code.

    ?View Code CSHARP
    string x = Res.OneOfMyStringNames;