1

How can I add a setting in c# settings.settings that will be in Boolean array type?

akjoshi
  • 15,374
  • 13
  • 103
  • 121
  • Related question regarding int arrays. Maybe the solutions presented there work for your case as well? http://stackoverflow.com/questions/1766610/how-to-store-int-array-in-application-settings – Heinzi May 23 '12 at 15:38

4 Answers4

0
<Setting Name="SettingName" Type="System.Boolean[]" Scope="User">
  ...

</Setting>
oddi
  • 387
  • 1
  • 3
  • 14
0

You can not set any kind of array type. If you want to use array values then you have to store it as XML file or as string and then in runtime you have to parse the XML file or string to get your exact value.

Md Kamruzzaman Sarker
  • 2,387
  • 3
  • 22
  • 38
0

You can create class:

public class BoolList : List<bool>
{
}

and then use this type.

0

Here is an alternative, go to your Settings and create a new Setting of type StringCollection, then click the ellipsis button (...) and enter each value,in a new line e.g. true or false. Then in your code you can read it like this:

List<string> list = Settings1.Default.StringArray.Cast<string>().ToList();
bool[] b_array = list.Select(x => x == "true").ToArray();

In my example I called my StringCollection property 'StringArray'

Your StringCollection setting will be stored as XML:

<?xml version="1.0" encoding="utf-16"?>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <string>true</string>
  <string>false</string>
  <string>true</string>
  <string>false</string>
  <string>false</string>
</ArrayOfString>

Hope this helps

David Gardiner
  • 16,892
  • 20
  • 80
  • 117
Adolfo Perez
  • 2,834
  • 4
  • 41
  • 61