读取配置方法有多种:
1、 通过 AppSettingsReader 读取相关配置
首先在应用程序上 右键 添加-> 新建项-> 选择 应用程序配置文件 ,系统会生成App.config文件
在配置文件中 设置相应的 键值对 如下
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<!-- 配置 -->
<add key="1" value="1-1"/>
<add key="2" value="22"/>
<add key="3" value="33"/>
</appSettings>
</configuration>
在代码中通过 AppSettingsReader 读取相关
代码如下:
AppSettingsReader pReader = new AppSettingsReader();
Type oType = typeof(System.String);
label1.Text = pReader.GetValue("1",oType).ToString(); // label1.Text 最终值为1-1