I sort of understand why this is happening, but not entirely. I have a base class with a Shared
(Static
) variable, declared like so:
Public Shared myVar As New MyObject(arg1, arg2)
In a method of a derived class, I set a local variable like so:
Dim myLocalVar As MyObject = myVar
Now when I do something like myLocalVar.Property1 += value
, the value in Property1
persists to the next call of that method! I suppose I get why it would be happening; myVar
is being set by reference instead of by value, but I've never encountered anything like this before. Is there any way (other than my workaround which is to just create a new object using the property values of myVar
) to create myLocalVar
by value?