Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Web.config or App.config keys are case insensitive?

Tags:

c#

.net

I am accessing the key from App.config in the class. If I give the key irrespective of case I am able to access its value.

I have checked that I am not doing ToLower() anywhere.

//The below is the key in App.config
<add key="Timezone_Minutes" value="+100"/>

//Accessing this key in class
 private static readonly string timezoneMinutes = ConfigurationSettings.AppSettings["TIMEZONE_MINUTES"];

I am getting the value +100 in timezoneMinutes. The key given in App.config is Timezone_Minutes, but accessing in class is TIMEZONE_MINUTES. But still I get the value. Is it case insensitive. I googled, but didn't get the proper answer.

like image 646
Shreeraj Bhat Avatar asked Sep 05 '19 12:09

Shreeraj Bhat


1 Answers

As per the docs (for the type returned by AppSettings):

The default comparer is a CaseInsensitiveComparer that uses the conventions of the invariant culture; that is, key comparisons are case-insensitive by default.

This is consistent with the behaviour you are seeing.

like image 124
mjwills Avatar answered Oct 29 '22 19:10

mjwills