views:

307

answers:

1

Assuming there are 5 items in the settings file (MySetting1 to MySetting5), why does PropertyValues have 0 items while Properties has the correct number?

Console.WriteLine( Properties.Settings.Default.PropertyValues.Count ); // Displays 0
Console.WriteLine( Properties.Settings.Default.Properties.Count );     // Displays 5
+3  A: 

It appears that PropertyValues refers to the number of PropertyValues that have been set. The default values you specify aren't considered set and won't be stored to the user config if you sall Save().

Console.WriteLine(Settings.Default.PropertyValues.Count.ToString());
Console.ReadLine();
Settings.Default.Setting = "abc";
Console.WriteLine(Settings.Default.PropertyValues.Count.ToString());
Console.ReadLine();

results in the following output:

0

1

James
It appears it's enough to do this: Settings.Default.Setting = Settings.Default.Setting;