如何从WinForms中的app.config中读取AppSettings [英] How to read AppSettings from app.config in WinForms

查看:136
本文介绍了如何从WinForms中的app.config中读取AppSettings的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通常使用文本文件作为配置.但是这次我想利用app.config将文件名(键)与名称(值)相关联,并在组合框中显示这些名称

I usually use a text file as a config. But this time I would like to utilize app.config to associate a file name (key) with a name (value) and make the names available in combo box

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
   <add key="Scenario1.doc" value="Hybrid1"/>
   <add key="Scenario2.doc" value="Hybrid2"/>
   <add key="Scenario3.doc" value="Hybrid3"/>
</appSettings>
</configuration>

这行得通吗?如何检索数据?

will this work? how to retrieve the data ?

推荐答案

直接从因此,如果要访问设置Scenario1.doc,请执行以下操作:

So, if you want to access the setting Scenario1.doc, you would do this:

var value = ConfigurationManager.AppSettings["Scenario1.doc"];

正如Gabriel GM在评论中所说,您将不得不添加对System.Configuration的引用.

As Gabriel GM said in the comments, you will have to add a reference to System.Configuration.

这篇关于如何从WinForms中的app.config中读取AppSettings的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆