C# 计算类文件中appconfig中的键数
我需要知道如何计算应用程序设置中的键数,并通过类文件中的键进行操作。。。 例如,我的应用程序配置如下C# 计算类文件中appconfig中的键数,c#,c#-4.0,app-config,configuration-files,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="My
<?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>
这里我可能没有钥匙。我需要计算这个项目的类文件中可用的键的数量。怎么做?您可以这样做:
var appSettings = System.Configuration.ConfigurationManager.AppSettings;
int cntAppSettingKeys = appSettings.Count;
是一个。所以下面的代码可以工作
System.Configuration.ConfigurationManager.AppSettings.Count