gpt4 book ai didi

c# - asp.net web.config appsettings 多个值

转载 作者:太空狗 更新时间:2023-10-29 20:08:30 24 4
gpt4 key购买 nike

我有一个看起来像这样的 appSetting block :

<appSettings>
<key="site1" value="http://www.thissite.com,site name" />
<key="site2" value="http://www.thissite.com,site name" />
</appSettings>

我想用值和文本填充下拉列表:

value="http://www.thissite.com" text="site name"

我可以使用这个将它们放入单独的数组中:

string[] mykey = ConfigurationManager.AppSettings["site1"].Split(',');
string[] mykey = ConfigurationManager.AppSettings["site2"].Split(',');

但是,我想将它们组合成一个数组,然后遍历并填充代码隐藏中的下拉列表。我可以通过循环遍历各个数组的方式填充它,但似乎必须有更好的方法来使用更少的代码。

谁能告诉我怎么做?


归功于你,但非常感谢 acermate433s' answer下面。

NameValueCollection appSettings = ConfigurationManager.AppSettings;
for (int i = 0; i < appSettings.Count; i++)
{
Response.Write(appSettings.GetKey(i).ToString() + "-" + appSettings[i].ToString());
}

显然,我要做的不仅仅是显示它。

最佳答案

AppSettings 是一个NameValueCollection,您可以使用for each

遍历它的所有值

关于c# - asp.net web.config appsettings 多个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6526738/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com