我正在类中的 App.config 访问 key 。如果我不分大小写地提供 key ,我就可以访问它的值。
我已经检查过我没有在任何地方执行 ToLower()。
//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"];
我在 timezoneMinutes 中得到值 +100。 App.config 中给定的键是Timezone_Minutes,但是在类中访问是TIMEZONE_MINUTES。但我仍然得到了值(value)。是否不区分大小写。我用谷歌搜索,但没有得到正确答案。
最佳答案
根据 the docs (对于 AppSettings
返回的类型):
The default comparer is a CaseInsensitiveComparer that uses the conventions of the invariant culture; that is, key comparisons are case-insensitive by default.
这与您看到的行为一致。
关于c# - Web.config 或 App.config 键是否不区分大小写?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57805920/