c# - 计算类文件中 appconfig 中的键数

标签 c# c#-4.0 app-config configuration-files

我需要知道如何计算应用程序设置中的键数并在类文件中操作它们... 例如,我的应用程序配置如下

<?xml version="1.0"?>
<configuration>
  <appSettings>
    <add key="Mysqlrateteller" value="server=localhost;Database=rateteller;User Id=root;Password=;"/>
    <add key="Mysqlrateteller1" value="server=localhost;Database=rateteller1;User Id=root;Password=;"/>
    <add key="Mysqlrateteller2" value="server=localhost;Database=rate;User Id=root;Password=;"/>
  </appSettings>

<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

这里我可能有 n 把 key 。我需要计算这个项目的类文件中可用的键数。怎么做?

最佳答案

你可以这样做:

 var appSettings = System.Configuration.ConfigurationManager.AppSettings;
 int cntAppSettingKeys = appSettings.Count;

关于c# - 计算类文件中 appconfig 中的键数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13410785/

相关文章:

c# - 如何使用C#检索同一域中的所有Office 365用户?

c# - 无法使用jquery从 Controller 获取数据

c# - 为什么在使用 "Including"时 FluentAssertions 中会忽略嵌套类?

.net - 通过 App.config 为 System.Net.HttpWebRequest 指定 SSL/TLS

c# - 运行单元测试时更改 app.config

c# - 如何延迟 Button.Flyout 的出现?

c++ - 如何将 IntPtr 类型的参数从 C# 项目传递到我的 COM DLL 项目

multithreading - 与线程相比,任务轻巧吗?

c# - 如何在 C# 中创建 “0000001” 类型数字格式?

oracle - 部署和配置 ODP.NET,使其无需安装 Entity Framework 即可工作