c# - Web.config 或 App.config 键是否不区分大小写?

标签 c# .net

我正在类中的 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/

相关文章:

c# - 编辑大型二进制文件

c# - 尝试从 ExpandoObject 获取动态属性时出现 "System.StackOverflowException"错误

c# - WCF 已超出传入消息的最大消息大小配额 (65536)

c# - 为什么这个特定的 PowerShell 命令在 .NET 6 中失败(它曾经在 .NET 4 中工作)

.net - 有没有办法在 VB .Net 函数中返回多种类型? (不是元组,如 PHP 内部函数)

c# - 跨程序集移动的反序列化类型

javascript - 修改 OpenLayers 3 中现有图层的值

c# - 从数据表中提取两件事的总和

c# - 在 C# 中编码 C 结构

c# - C#中线程的合理使用?