asp.net - 将字符串数组存储在 appSettings 中?

标签 asp.net .net web-config app-config asp.net-4.0

我想将一维字符串数组存储为我的 appSettings 中的条目。我不能简单地用 | 分隔元素,因为元素本身可能包含这些字符。

我正在考虑将数组存储为 JSON,然后使用 JavaScriptSerializer 对其进行反序列化。

是否有“正确”/更好的方法来做到这一点?

(我的 JSON 想法感觉有点老套)

最佳答案

您可以将 AppSettings 与 System.Collections.Specialized.StringCollection 一起使用.

var myStringCollection = Properties.Settings.Default.MyCollection;
foreach (String value in myStringCollection)
{ 
    // do something
}

每个值都用换行符分隔。

这是一个屏幕截图(德语 IDE,但无论如何它可能会有所帮助)

enter image description here

关于asp.net - 将字符串数组存储在 appSettings 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10419116/

相关文章:

c# - 将图像从android上传到ASP.NET服务器C#

c# - VSTO PowerPoint/Excel 交互

c# - 如何提供属性级字符串格式?

c# - 我在哪里可以得到 NLog 提供的 "ambient properties"的列表?

web-config - 4.6.1 框架更新使 web.config httpRuntime 仍为 4.5?

c# - 替代 web.config 中的 appsettings(需要持久性)

javascript - 如何在不向元素添加 runat=server 的情况下修改 ASP.NET 页面中的 HTML 和 BODY 标记?

javascript - 为什么 w3css 侧导航栏在 Asp.net 母版页中不起作用?

asp.net - 如何防止js文件重定向登录?

redirect - 带有缓存响应 header 的 IIS 重定向