Reputation: 669
Is it possible to get the key based on app settings value?
for Example;
string value = "abcd";
string key = ConfigurationManager.AppSettings[value].ToString();
Now, I want the CustomerCategory
in key
variable.
Upvotes: 0
Views: 992
Reputation: 547
If I'm not misunderstood your question, Here's the way to do it.
app.config file should be like this,
<appSettings>
<add key="myKey" value="myValue"/>
</appSettings>
And your C# code
string myValue = ConfigurationManager.AppSettings["myKey"];
Upvotes: 0
Reputation: 100358
using System.Linq;
string key = ConfigurationManager.AppSettings.AllKeys.FirstOrDefault(k =>
ConfigurationManager.AppSettings[k] == value);
Upvotes: 2