本文介绍了C#:为什么设置PropertyValues有0项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设设置文件中有5个项目(MySetting1到MySetting5),为什么PropertyValues有0个项目,而属性具有正确的数字?
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
推荐答案
看来PropertyValues是指已设置的PropertyValues数。您指定的默认值不会被视为设置,如果您使用Save(),则不会将其存储到用户配置中。
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();
会产生以下输出:
0
1
这篇关于C#:为什么设置PropertyValues有0项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!