Reputation: 1412
I have been programming for some time, but I have some fundamental questions, one of them is as follows:
Public Class PriceListDetails
Dim pricelist As BSPLib.PriceLists.PriceList
Dim IsReadOnly1 As Boolean
Public Sub New(ByVal IsReadonly2 As Boolean)
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
'Readonly prevents from Modifying/Saving
IsReadOnly1 = IsReadonly
End Sub
End Class
Is it compulsory to create IsReadyOnly1 and IsReadyOnly2, is there a way to take the parameter from new method to IsReadyOnly1 Directly like in reference type?
Thank you.
Upvotes: 1
Views: 83
Reputation: 869
Setting members with constructor parameters is pretty much common practice in OOP. However, if you are using public properties then you could use object initializers as well:
Dim priceList1 = New PriceListDetails With {.IsReadOnly = True}
Upvotes: 2
Reputation: 20745
Boolean is not reference type variable, so it's not possible.
In case you want to copy the reference,then also you need both variable. You can take only IsReadonly2 as reference.
Upvotes: 0
Reputation: 941455
Hard to tell what you mean, the posted code cannot compile. I'll suppose you mean this:
Private IsReadOnly As Boolean
Public Sub New(ByVal IsReadOnly As Boolean)
InitializeComponent()
Me.IsReadOnly = IsReadOnly
End Sub
Where the Me keyword ensures that the field is assigned instead of the parameter.
Upvotes: 2