views:

662

answers:

1

I am looking for a neat/clean way to store a list of strings into a C# settings file. As far as I can work out, you can't store List objects into these settings, so basically it needs to be converted to a string. For example, say I have a list of names:

  • N*a*m*e*A
  • Name;B
  • Complex, Weird, Name
  • Name"nickname"Person

i.e. I am trying to demonstrate a list of names which can possibly contain any character. Does anyone have any recommendations for a neat format + Regex to read it that can handle any character? Or possibly an easy way to serialize a List<string>?

Currently, I am saving them as a simple command delimited string which works fine so long as you are careful with the names (can't have commas), but is destined to break down the line.

+4  A: 

You can select the type of your setting entry as

System.Collections.Specialized.StringCollection

from the Properties.Settings tab.

This will be translated into your config file as something like

 <ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
  <string>string1</string>
  <string>string2</string>
 </ArrayOfString>
Manu