Store String Array with Values in Application Settings [duplicate]
Asked Answered
S

1

18

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;

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.

cannot convert to System.String

Does anyone know the correct syntax? I'm also open to using a StringCollection if that's easier.

Sundew answered 21/11, 2013 at 19:45 Comment(4)
You try to convert string containing C# code of array initialization "new string[] { .... }" to string[].Calix
maybe this can help: #1767110Grassofparnassus
@Calix so what should I be doing? I have tried many, many different variants.Sundew
@SebastianPiu I tried throwing that entire XML string into the box and it complained as well.Sundew
M
31

Try to use StringCollection instead of string[]. It is natively supported by the settings designer.

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.

enter image description here

Moldboard answered 21/11, 2013 at 19:50 Comment(2)
Do you know what to type in the value field in my Settings.settings file with a StringCollection?Sundew
Full name System.Collections.Specialized.StringCollectionFoeticide

© 2022 - 2024 — McMap. All rights reserved.