2

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

<?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>

在这里我可能没有钥匙。我需要计算这个项目的类文件中可用的键的数量。怎么做?

4

2 回答 2

1

你可以这样做:

 var appSettings = System.Configuration.ConfigurationManager.AppSettings;
 int cntAppSettingKeys = appSettings.Count;
于 2012-11-16T05:09:04.617 回答
0

AppSettings是一个NameValueCollection。所以下面的代码将起作用

 System.Configuration.ConfigurationManager.AppSettings.Count
于 2012-11-16T05:37:33.890 回答