在应用程序设置中存储带有值的字符串数组 [英] Store String Array with Values in Application Settings
问题描述
我修改了我的 Settings.settings 文件,以使 system_Filters
成为 System.String[]
.
我想在 Visual Studio 设计器中而不是在代码中填充这个变量.我可以使用以下代码让它在代码中工作:
I've modified my Settings.settings file in order to have system_Filters
be a System.String[]
.
I would like to populate this variable within the Visual Studio designer and not from within the code. I can get it to work within the code using the following:
Properties.Settings.Default.system_Filters = new string[] { "a", "b", "c" };
string _systemFilters = Properties.Settings.Default.system_Filters;
这可以正常工作.但是,我没有一个好地方可以将它放入我的代码中,理想情况下希望将它输入到 Settings.setting 文件中.该值不会被修改.我尝试了几乎所有我能想到的变体,但结果总是一样的.
This works correctly. However, I don't have a nice place to put this in my code and ideally want to type it in the Settings.setting file. This value will not be modified. I've tried almost every variant I can think of, but the result is always the same.
有人知道正确的语法吗?如果这样更容易,我也愿意使用 StringCollection
.
Does anyone know the correct syntax? I'm also open to using a StringCollection
if that's easier.
推荐答案
尝试使用 StringCollection
而不是 string[]
.设置设计器本身支持它.
Try to use StringCollection
instead of string[]
. It is natively supported by the settings designer.
该值存储为 XML,但您无需手动编辑它.当你在 Type 列中选择 StringCollection
时,Value 列中的编辑器发生了变化;有一个 ... 按钮,它会打开一个对话框来输入字符串.
The value is stored as XML, but you don't need to edit it manually. When you select StringCollection
in the Type column, the editor in the Value column changes; there is a ... button, which opens a dialog to type the strings.
这篇关于在应用程序设置中存储带有值的字符串数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!