开发者

Global Variables

开发者 https://www.devze.com 2023-03-16 19:38 出处:网络
In my WPF applciation I would like to use global variable, the purpose is like to store the current user information etc, The problem is that, there are two methods for it and they are:

In my WPF applciation I would like to use global variable, the purpose is like to store the current user information etc, The problem is that, there are two methods for it and they are:

Application.Current.Properties vs My.Settings

I know that using My.Settings, the changes will be stored and when the app restarts or reopened, they would load the last saved ones, I dont want it this way. Could you please clarify is Application.Current.Property solve my problem or is there any other method for th开发者_StackOverflowis.

Thank you.


Why not just create a static or singleton class to hold all your values, if your going to reload them every time the program is going to run anyway?

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 Class
0

精彩评论

暂无评论...
验证码 换一张
取 消