I do not think that you understand
pointers.
I know that it is a c++/c# term, but it is a very important concept to comprehend.
Whenever you declare a variable for a class, that variable Points to a location in memory where the class's data begins (well, kind of but we'll keep it simple).
If you set ObjectVariableA = ObjectVariableB you are are changing ObjectVariableA's pointer to point to the memory location that ObjectVariableB is pointing to.
Pointers do not apply to
primitive variable types like Decimal, or String. If you set DecimalA=5 and DecimalB=10 and then you set DecimalA=DecimalB....and then you change one, the other will not change.
You really should check out this MSDN article about
Value Types and Reference Types
So, the following code will set the variable
largestAreaGen
to point to the gen Object instance that contains the largest area.
It will then print the area property of the gen instance that the
largestAreaGen
variable points to.
-
Public Sub main()
-
Dim allGens As New List(Of Gen)
-
Dim fixedRand As New Random(CInt(Date.Now.Ticks And &h0000FFFF))
-
For i As Integer=1 to 10
-
Dim g As New Gen
-
g.len = fixedRand.NextDouble()' just a random number
-
g.area = g.len * g.len
-
allGens.Add(g)
-
Next
-
-
Dim largestAreaGen As New Gen
-
largestAreaGen.area = -1
-
-
For Each a As Gen In allGens
-
If a.area > largestAreaGen.area Then
-
largestAreaGen = a
-
End If
-
Next
-
MessageBox.Show("maximum random Area was=" & largestAreaGen.area)
-
End Sub
-Frinny