![]() ![]() | ||
You can make properties shared with the Shared keyword, which means you can use them with the class name, and don't need a specific object to work with. However, in a shared property, you can only work with shared data, or data passed to you, or you must provide a specific object to work with. Here's an example where I'm creating and working with a shared property:
Public Class Mathematics Shared Data As Integer = 0 Shared Property Property1() Get Return Data End Get Set(ByVal Value) Data = Value End Set End Property End Class Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click Mathematics.Property1 = 5 End Sub Private Sub Button2_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button2.Click TextBox1.Text = Mathematics.Property1 End Sub
Related solution: |
Found on page: |
---|---|
132 |
![]() ![]() | ||