【发布时间】:2018-03-17 22:46:09
【问题描述】:
我需要修改以下 C# 程序,从 config.app 中读取所有三个字母 abbreviationthe country name 并将其列在 winForm 组合框上,并从组合框中进行选择以相应地更新 lbCountry.Text 和 lbCurrencyRate.Text。
我是 C# 新手,不确定如何使用以下详细信息更新 app.config 并根据组合框的选择检索它们。希望有人能帮忙。
国家缩写:美国
国名:美国
汇率:1.00
国家缩写:澳大利亚
国名:澳大利亚
汇率:0.80
国家缩写:GBR
国家名称:英国
汇率:0.76
国家缩写:JPN
国名:日本
汇率:113.00
以下是最初创建的部分代码,用于从 app.config 中检索一个国家/地区的详细信息。
private void Main_Load(object sender, EventArgs e)
{
string countryName = ConfigurationManager.AppSettings.Get("COUNTRY_NAME");
string currencyRate = ConfigurationManager.AppSettings.Get("CURRENCY_RATE");
lbCountry.Text = string.Format("Country Name: {0}", countryName.ToString());
lbCurrencyRate.Text = string.Format("Currency Rate: {0}", currencyRate.ToString());
......
}
App.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="COUNTRY_NAME" value="United States of America" />
<add key="CURRENCY_RATE" value="1.00" />
</appSettings>
......
</configuration>
【问题讨论】:
-
最好存储在单独的 xml 中。
标签: c# wpf winforms combobox app-config