Reputation: 2886
I have an application that is multilingual. I'm using the out-of-the-box .Net features for this. Each language has its own file in the App_GlobalResources (see iamge below)
In the code behind what is better?
The 2nd one uses less code and it's type safe, it will return an error during compile time and not run time.
alt text http://img340.imageshack.us/img340/5562/langl.gif
Upvotes: 4
Views: 3310
Reputation: 25704
These are the advantages of each approach:
Advantages of GetGlobalResourceObject
(and GetLocalResourceObject
):
Advantages of strongly-typed RESX types:
So, as with many "which is best" questions, the answer is: It depends! Choose the one that has advantages that will benefit your particular scenarios the most.
Upvotes: 8
Reputation: 25200
So use the second one, if you know up-front what the resource file and key will be.
The GetGlobalResourceObject()
method is useful if you don't know what the resource file or (more likely) the key will be at compile time.
Upvotes: 2