c# - 在应用程序设置中存储带值的字符串数组

标签 c# visual-studio .net-4.5 application-settings settings.settings

<分区>

我已经修改了我的 Settings.settings 文件,以便让 system_Filters 成为 System.String[]
我想在 Visual Studio 设计器中而不是在代码中填充此变量。我可以使用以下代码让它在代码中工作:

Properties.Settings.Default.system_Filters = new string[] { "a", "b", "c" };
string _systemFilters = Properties.Settings.Default.system_Filters;

这工作正常。但是,我没有不错的地方可以将它放入我的代码中,理想情况下我想将它输入到 Settings.setting 文件中。该值不会被修改。我几乎尝试了所有我能想到的变体,但结果总是一样。

cannot convert to System.String

有人知道正确的语法吗?如果这样更容易,我也愿意使用 StringCollection

最佳答案

尝试使用 StringCollection 而不是 string[]。它由设置设计器原生支持。

该值以 XML 格式存储,但您无需手动对其进行编辑。当您在 Type 列中选择 StringCollection 时,Value 列中的编辑器会发生变化;有一个 ... 按钮,它会打开一个对话框来键入字符串。

enter image description here

关于c# - 在应用程序设置中存储带值的字符串数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20130448/

相关文章:

c# - 使用 Azure Function V3,如何将现有的 Ilogger 注入(inject)到新的类文件中?

c# - System.Reflection.RuntimeReflectionExtensions 中方法的目的是什么?

c# - 工作流基础 4.5 "Expression Activity type ' CSharpValue` 1' requires compilation in order to run."

wpf - WPF XPath 表达式中的过滤器

c# - 对于 C# 任务,在检查 .Result 之前是否需要 Wait()?

xml - Azure部署: error MSB4041: The default XML namespace of the project must be the MSBuild XML namespace

c# - 获取从 BindingSource 到表/数据集的过滤结果?

.net - 使用 Git Extensions for Visual Studio 将单个文件恢复为早期提交

c# - 有没有人有使用 betfair api 的 c# 代码?

c# - 在 F# 中创建本地函数