开发者

How to assign a conditional value prior to get/set in ascx vb.net

开发者 https://www.devze.com 2023-02-26 05:38 出处:网络
In the members region I declare _Name and assign it the value \"NameA\" but how do I assign this value conditionally?

In the members region I declare _Name and assign it the value "NameA" but how do I assign this value conditionally?

The idea is that if in some file there's a value set than that should be the default value and not the hard coded one, if non is set the hard coded one should stick.

Is there an official good way of doing this or is or is wrecking the get/set the only way to accomplish this?


#Region "Members"
    Private _Name As String = "NameA"
#End Region

#Region "Properties"
    Public Property Name() As String
        Get
            Return _Name
        End Get
        Set(ByVal value As String)
            _Name = value
        En开发者_运维技巧d Set
    End Property
#End Region


Maybe your problem is the way your looking to that.

if you explicitly declare a variable assigning a value, you loose the "dynamic requirement", if you are creating a class with properties, properties are the good way to expose a private member.

if you what to create a instance of this class assigning different values, why you dont pass that info by parameters on the class contructor?

0

精彩评论

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