在我的WPF应用程序中,我想使用全局变量,目的是存储当前用户信息等,问题是,有两种方法可以实现它,它们是:
Application.Current.Properties vs My.Settings
我知道使用My.Settings,更改将被存储,当应用程序重新启动或重新打开时,它们将加载最后保存的内容,我不希望这样。你能澄清一下是Application.Current.Property解决了我的问题,还是有其他方法可以解决这个问题?
谢谢。
发布于 2011-07-01 06:08:04
为什么不创建一个静态或单例类来保存所有的值,如果每次程序都要运行时都要重新加载它们呢?
Public Class Globals
Public Shared Property One As String
Get
Return TryCast(Application.Current.Properties("One"), String)
End Get
Set(value As String)
Application.Current.Properties("One") = value
End Set
End Property
Public Shared Property Two As Integer
Get
Return Convert.ToInt32(Application.Current.Properties("Two"))
End Get
Set(value As Integer)
Application.Current.Properties("Two") = value
End Set
End Property
End Classhttps://stackoverflow.com/questions/6541630
复制相似问题