Apologies for the appalling title.
I have mocked up this code to mimic an issue I was encountering on a project.
I want to know why the property status does not 'stick'. Stepping through the code I can even see it setting the property!
Is it something to do with Structure being a value type?
Here is the code, it is standalone.
Imports System.Diagnostics
Public Class clsTest
Public Shared Sub test()
Dim myHolder As New holder
myHolder.info = New info(5)
With myHolder.info
Debug.Print("Initialised Status : {0}", .status)
Debug.Print("Initialised Original Status : {0}", .originalStatus)
myHolder.setStatusToTen()
Debug.Print("Next Status : {0}", .status)
Debug.Print("Next Original Status : {0}", .originalStatus)
End With
End Sub
End Class
Public Class holder
Private _heldInfo As info
Public Property info() As info
Get
Return _heldInfo
End Get
Set(ByVal value As info)
_heldInfo = value
End Set
End Property
Public Sub setStatusToTen()
_heldInfo.status = 10
End Sub
End Class
Public Structure info
Private _iOriginalStatus, _iStatus As Integer
Public Sub New(ByVal iStartingStatus As Integer)
_iOriginalStatus = iStartingStatus
End Sub
Public ReadOnly Property originalStatus() As Integer
Get
Return _iOriginalStatus
End Get
End Property
Public Property status() As Integer
Get
Return _iStatus
End Get
Set(ByVal value As Integer)
_iStatus = value
End Set
End Property
End Structure
When I run clsTest.test
I get the following output-
clsTest.test
Initialised Status : 0
Initialised Original Status : 5
Next Status : 0
Next Original Status : 5
...even though setStatusToTen
is doing exactly what it says on the tin!