Quantcast
Channel: Jamie Dixon » ASP.NET
Viewing all articles
Browse latest Browse all 3

Global Resource strings by property

$
0
0

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;

Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images