Ok, while this is pretty basic stuff, I found my self explaining this on my current gig to some VB 6 guys that we are helping get up to speed on .Net. They came to me and asked why the following code doesn't work. (point gets updated but _point(i) doesn’t)
**No, VB is not my language of choice, but I can do the C# >VB another time.
Doesn't work
Private _points As New List(Of PointF)
Dim point As New PointF
_points.Add(New PointF(0, 100))
_points.Add(New PointF(0, 100))
_points.Add(New PointF(100, 100))
_points.Add(New PointF(100, 0))
For Each point In _points
point.X += Base.X
point.Y += Base.Y
Next
(To be honest, I didn't have an explanation right away, as I didn't realize that PointF is a stuct, as I haven't worked with GDI+ before. I did feel dumb when I did realize PointF was a stuct. DOH!)
Does Work
Private _points As New List(Of PointF)
Dim point As PointF
_points.Add(New PointF(0, 100))
_points.Add(New PointF(0, 100))
_points.Add(New PointF(100, 100))
_points.Add(New PointF(100, 0))
For index As Integer = 0 To _points.Count - 1
point = _points.Item(index)
point.X += Base.X
point.Y += Base.Y
_points.Item(index) = point
Next
In the first code, point, being a struct (value type), becomes an independent copy of _points(i). In the second code we are updating the reference to the new copy.
Other considerations when using value types in generic list can be found here
http://msdn2.microsoft.com/en-us/library/6sh2ey19.aspx