shanecox704
New member
- Joined
- Mar 9, 2009
- Messages
- 1
- Programming Experience
- 3-5
Hello i'm a tad confused here.
I kinda new to generics, i thought that i was understanding it all fine now this,
My Problem;
I have a basic generic class
Public Class Characteristic(Of T)
Private mCharacteristicName As String
Private mCharacteristicValue As T
' Private mType As Type
Private mDominant As Boolean
Private mEnabled As Boolean
Public Sub New(ByVal CharacteristicName As String, ByVal CharacteristicValue As T, ByVal Dominant As Boolean, ByVal Enabled As Boolean)
mCharacteristicName = CharacteristicName
mCharacteristicValue = CharacteristicValue
mEnabled = Enabled
mDominant = Dominant
End Sub
Called By this function
Friend Sub FoundFood(ByVal foodSize As Single)
If ((mCharacteristics.Size.CharacteristicValue + foodSize) < mCharacteristics.MaxSize.CharacteristicValue) Then
Me.mCharacteristics.Size.CharacteristicValue += foodSize
Else
Me.mCharacteristics.Size.CharacteristicValue = Me.mCharacteristics.MaxSize.CharacteristicValue
End If
Me.IncFitness()
End Sub
My problem is, somehow when the line
"Me.mCharacteristics.Size.CharacteristicValue += foodSize "
is called, all instaces of mCharacteristics.size are updated not just the local (current) Size and i have no idea why.
If you need more info please ask,
Thanks
Shane
I kinda new to generics, i thought that i was understanding it all fine now this,
My Problem;
I have a basic generic class
Public Class Characteristic(Of T)
Private mCharacteristicName As String
Private mCharacteristicValue As T
' Private mType As Type
Private mDominant As Boolean
Private mEnabled As Boolean
Public Sub New(ByVal CharacteristicName As String, ByVal CharacteristicValue As T, ByVal Dominant As Boolean, ByVal Enabled As Boolean)
mCharacteristicName = CharacteristicName
mCharacteristicValue = CharacteristicValue
mEnabled = Enabled
mDominant = Dominant
End Sub
Called By this function
Friend Sub FoundFood(ByVal foodSize As Single)
If ((mCharacteristics.Size.CharacteristicValue + foodSize) < mCharacteristics.MaxSize.CharacteristicValue) Then
Me.mCharacteristics.Size.CharacteristicValue += foodSize
Else
Me.mCharacteristics.Size.CharacteristicValue = Me.mCharacteristics.MaxSize.CharacteristicValue
End If
Me.IncFitness()
End Sub
My problem is, somehow when the line
"Me.mCharacteristics.Size.CharacteristicValue += foodSize "
is called, all instaces of mCharacteristics.size are updated not just the local (current) Size and i have no idea why.
If you need more info please ask,
Thanks
Shane