Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 计算类文件中appconfig中的键数_C#_C# 4.0_App Config_Configuration Files - Fatal编程技术网

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