猿问

这两种情况的差别是什么呢? 数据保存到了哪里? 这个是C# 不是C++ 分错类了?

我存的时候:
Properties.Settings.Default.UID==TextBox1.Text;
Properties.Settings.Default.Save();
如果我这样保存,我下次及时关闭了程序,还能读出来
--------------------------------------------------
如果这样保存:
Properties.Settings.Default.Properties["UID"].DefaultValue = txtUID.Text;
我要是这么存,下次关闭了程序,就读不出来

一只甜甜圈
浏览 333回答 3
3回答

月关宝盒

你都看到了,这里你调用的是Properties["UID"].DefaultValue,也就是设置了属性的默认值!这样是不对的,请直接赋值,如Properties["UID"]= txtUID.Text;你可以看看系统帮你生成的那个属性的代码是怎么赋值的,肯定是这样的:[UserScopedSettingAttribute()]public String UID{get { return (String)this["UID"]; }set { this["UID"] = value; }}

萧十郎

DefaultValue和Value不一样,可以在Setting.Designer.cs里看到自动生成的代码是:[global::System.Configuration.UserScopedSettingAttribute()][global::System.Diagnostics.DebuggerNonUserCodeAttribute()][global::System.Configuration.DefaultSettingValueAttribute("9")]public int UID {get {return ((int)(this["UID"]));}set {this["UID"] = value;}}Value设置的是属性值,DefaultValue设置的是那个DefaultSettingValueAttribute的值,这个是在Reload()是读取的,一般的时候读取的时候是Value,当然设置属性值之后都需要Save(),保存当前属性值。

SMILET

Properties.Settings.Default.UID=TextBox1.Text;//这句赋值Properties.Settings.Default.Save();//这句保存Properties.Settings.Default.Properties["UID"].DefaultValue = txtUID.Text;这个没保存吧。数据存放在;项目目录下:Properties/Settings.Settings文件里
随时随地看视频慕课网APP
我要回答