如: [html] view plaincopyprint? 1.
当前位置:文档之家› C#的App.config文件的配置与读取

C#的App.config文件的配置与读取

对于需要配置的常量,在App.config中进行配置,格式为:
<add key="变量名" value="变量值">如:
[html]view plaincopyprint?
1.<?xml version="1.0" encoding="utf-8" ?>
2.<configuration>
3. <appSettings>
4. <add key="SourceFolder" value="D:\CodeFolder\MysolutionTest
"/>
5. <add key="FindingString" value="要搜索的字符串"/>
6. <add key="OutputFile" value="E:\test\result.txt"/>
7. </appSettings>
8.</configuration>
在主程序中,需要读取App.config文件中配置的变量,采用NameValueCollection appSettings =
System.Configuration.ConfigurationManager.AppSettings;
来获取各个变量名和变量值。


NameValueCollection appSettings =
System.Configuration.ConfigurationManager.AppSettings;
string path = appSettings["SourceFolder"];在主程序中,需要读取
App.config文件中配置的变量,采用
NameValueCollection appSettings =
System.Configuration.ConfigurationManager.AppSettings;
来获取各个变量名和变量值。


[csharp]view plaincopyprint?
ValueCollection appSettings = System.Configuration.Configur
ationManager.AppSettings;
2.string path = appSettings["SourceFolder"];。

相关主题