Is the following simplification possible in the VB.NET?
Example: text
variable pointing to another string:
Class Form1
Sub New()
Dim text As (what_type?) = AddressOf TextBox1.Text 'simplification
If text = "foo" Then text = "bar" 'actually accessing TextBox1.Text
End Sub
End Class
I think it is not possible, but I can be wrong.
VB.NET doesn't have pointers. You can use properties:
Public Property Text As String
Get
Return TextBox1.Text
End Get
Set(value As String)
TextBox1.Text = value
End Set
End Property
You can use properties as layer to not expose the control itself but only relevant informations:
If Text = "foo" Then Text = "bar"
On this way you could even change the control(f.e. to Label
) without breaking code.
Another approach is using a lambda expression:
Dim setText = Sub(str As String) TextBox1.Text = str
setText("test")
Dim getText = Function() TextBox1.Text
Dim text As String = getText()
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments