DarkLeafyGreen
DarkLeafyGreen

Reputation: 70416

Concatenate variable names in c#

In my wp7 application I do a web request that returns a status code like 100, 110, etc. Each status code is associated with a status message. This status messages are localized in my application.

E.g.

m100 'OK'
m110 'Text was empty'

I want to show this text in a message box like this. contents gives us the status code as string value.

var s = 
    MessageBox.Show(AppResources.m100, AppResources.Notice, MessageBoxButton.OK);

But I don't want to specify a message box for each message. I want to handle this in a dynamic way like this.

var s = 
    MessageBox.Show(AppResources.m+contents, AppResources.Notice, 
                    MessageBoxButton.OK);

Any idea how to do this?

Upvotes: 0

Views: 307

Answers (1)

svick
svick

Reputation: 244878

You should be able to use the ResourceManager to get the value:

AppResources.ResourceManager.GetString("m" + contents)

Upvotes: 4

Related Questions