【问题标题】:How to force VB.NET to refresh the initial value for a variable without rewriting the initial formula如何在不重写初始公式的情况下强制 VB.NET 刷新变量的初始值
【发布时间】:2023-02-23 16:37:15
【问题描述】:

I want to refresh a variable for example path that I initially declared as Private path As String = My.Computer.Registry.GetValue(keyName, "path", path) but when i change the variable "keyname" the variable path doesn't change, is there a way to refresh it. for an easier example I would say we declared initially: private a as integer= b+c and then we change the value of b or c how do we get the new a value?

I tried making the variable a property but i couldn't understand how to use it well.

    标签: vb.net


    【解决方案1】:

    一种选择是使 keyName 成为一个属性,并在设置器中为路径变量分配一个新值。

    Public Property keyName() As String
            Get
                Return _keyName
            End Get
            Set(ByVal value As String)
                _keyName = value
                path = My.Computer.Registry.GetValue(value, "path", path)
            End Set
    End Property
    

    【讨论】:

    • 抱歉,我没有提到它,我的键名是两个字符串的串联:userRoot & "" & subkey,如果我要将键名转换为一个属性,我应该把这个串联放在哪里?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多