Trying to fill up an array of dates... where's my error ? help pls...

Hey, how are you ?

Could someone please tell what’s wrong with this code ?
I want to fill up the property ‘arraydates’ adding the dates starting today and moving forward up to the listboxgraph columncount.
I get an array full of the same values !
What am I doing wrong ?

dim first as new date

for a as integer = 1 to ListboxGraph.ColumnCount
Arraydates(a) = first
first.Day = first.Day+1
next

dim first as new date
for a as integer = 1 to ListboxGraph.ColumnCount
dim newDate as new date
newDate.totalseconds=first.totalseconds
Arraydates(a) = newDate
first.Day = first.Day+1
next

you are putting “first” into each array instance. First is a POINTER, so when you change its value, ALL the array values change because they all point to the same instance.
This code above, create a NEW instance for each array index, and uses the VALUE from first to set the value of the new date

Thanks a LOT Dave for the quick lesson!

With the date you assign an object to your array, not a pure data type like an integer.
While for the latter you really move the value, when you are assigning an object you only move the pointer to the memory space this object represents. So you basically assign all array items the same value, namely the pointer to first. And that has the last value of course.
Like Dave said in exactly this minute, make every day a really new object by using new in your loop.