TY, is there a easy workaround?
Mr. Arnold - 13 Jun 2007 06:55 GMT
> TY, is there a easy workaround?
Dim cat1 as new cat // It is its own cat. It is its own object
Dim cat2 As new cat // It is its own cat. It is its own object
You deal with each cat/object separately. And you don't cat2 = cat1.
Your way of
Dim cat1 as new cat ' Cat1 is its own cat. It is its own object.
dim cat2 as cat ' Cat2 is not its own cat. It was not born with
the (new) keyword.
' Cat2 only has
characteristics/properties of being a (cat).
and then setting cat2 = cat1 set reference to cat1 they are the same cat at
that point.
You do something to cat2, you're doing it to cat1. You use cat2, you're just
getting cat1, because the pointer for cat2 is pointing to cat1. Cat1 is the
only cat that's there and alive.
Jack Jackson - 13 Jun 2007 18:23 GMT
>TY, is there a easy workaround?
If your class is really as simple as your example, you could add a
constructor that takes a reference to an existing instance and sets
the properties of the new instance look like the existing instance:
Sub Main()
Dim cat1 As New cat
Dim cat2 As cat
cat1.Color = ConsoleColor.Black
cat2 = New cat(cat1)
cat2.Color = ConsoleColor.Blue
Trace.WriteLine(cat1.Color.ToString)
End Sub
Public Class cat
Dim mColor As ConsoleColor
Public Property Color() As ConsoleColor
Get
Return mColor
End Get
Set(ByVal value As ConsoleColor)
mColor = value
End Set
End Property
Sub New(_cat as cat)
Me.Color = _cat.Color
End Sub
End Class
Jared - 17 Jun 2007 23:02 GMT
Thanks, your answer was the best solution.