在 appSettings 中存储字符串数组? [英] Store String Array In appSettings?

查看:72
本文介绍了在 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)

推荐答案

您可以使用带有 System.Collections.Specialized.StringCollection.

You could use the AppSettings with a System.Collections.Specialized.StringCollection.

var myStringCollection = Properties.Settings.Default.MyCollection;
foreach (String value in myStringCollection)
{ 
    // 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屋!

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