C# 将数组添加到 web.config 中的键
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11728491/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 18:58:48 来源:igfitidea点击:
Add array to key in web.config
提问by user1269625
I was wondering if its possible to put an array as a value in a key...example
我想知道是否可以将数组作为值放入键中...示例
<add key="email" value="emails["[email protected], [email protected]"] />
Would that syntax work?
那个语法行得通吗?
采纳答案by Matthew
With ConfigurationManager.AppSettingsyou can only retrieve scalar values. For your example, if you seperate your emails with a semicolon, you can do:
随着ConfigurationManager.AppSettings你只能检索标量值。对于您的示例,如果您用分号分隔电子邮件,则可以执行以下操作:
string[] emails = ConfigurationManager.AppSettings["email"].Split(';');
with the web.config
使用 web.config
<add key="email" value="[email protected];[email protected]" />

