开发者

how to get the key name from app settings with associated with value in app settings

开发者 https://www.devze.com 2023-04-01 04:42 出处:网络
can anyo开发者_运维技巧ne tell me how to get the key name associated with a value in <app settings> Not entirely clear what you want to achieve here, but you could always just iterate over all a

can anyo开发者_运维技巧ne tell me how to get the key name associated with a value in <app settings>


Not entirely clear what you want to achieve here, but you could always just iterate over all appSettings and compare their values. If you find the one you're looking for take it's key.

            foreach (string key in Configuration.AppSettings.Settings.AllKeys)
            {
                string value = appSettings.Settings[key].Value;

                if (value.Equals(myValue))
                {
                     Console.WriteLine("Found Key: " + key);
                     break;
                }
            }

NOTE: The reverse mapping from value to key is of course not necessarily unique, i.e. you would have to deal with the fact, that the value you're using a search predicate matches more than one key.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号