存储字符串数组中的appSettings? [英] Store String Array In appSettings?
问题描述
我要存储一个一维字符串数组作为我的的appSettings
的条目。我能与不能简单地分开的元素,
或 |
,因为元素本身可能包含这些字符
I'd like to store a one dimensional string array as an entry in my appSettings
. I can't simply separate elements with ,
or |
because the elements themselves could contain those characters.
我在想存储阵列的 JSON
然后用反序列化 JavaScriptSerializer
。
I was thinking of storing the array as JSON
then deserializing it using the JavaScriptSerializer
.
有没有正确的/更好的方式来做到这一点?
Is there a "right" / better way to do this?
(我的 JSON
的想法感到有点哈克)
(My JSON
idea feels kinda hacky)
推荐答案
您可以使用一个<一的的AppSettings href="http://msdn.microsoft.com/en-us/library/system.collections.specialized.stringcollection.aspx"><$c$c>System.Collections.Specialized.StringCollection$c$c>.
You could use the AppSettings with a System.Collections.Specialized.StringCollection
.
var myStringCollection = Properties.Settings.Default.MyCollection;
foreach (String value in myCollection)
{
// do something
}
每个值由一个新行分隔。
Each value is separated by a new line.
下面是截图(德国IDE,但它可能会有所帮助呢)
Here's a screenshot (german IDE but it might be helpful anyway)
这篇关于存储字符串数组中的appSettings?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!