Using Find method on a List(of type) Breaks the Reference

  • Thread starter Thread starter muskito.net
  • Start date Start date
M

muskito.net

Hi,

I Have the following code:

Public Sub UpdateEvent(ByVal ID As Integer, _
ByVal StartTime As Integer, _
ByVal Duration As Integer)
EventId = ID
Dim EventToUpdate As SchedulerEvent =
SchedulerEvents.Find(AddressOf FindById)
EventToUpdate.StartTime = StartTime
EventToUpdate.Duration = Duration
End Sub

SchedulerEvent is a Structure
SchedulerEvents is a List(of SchedulerEvent)

When i run this, the Find method Does find the correct object
corresponding to the ID Supplied.
However - When I Update the StartTime and Duration of the object - it
does not update the actual list...
when i tried to check whether the reference between the two equals
using:
SchedulerEvent.ReferenceEquals(SchedulerEvents(1),EventToUpdate)
(I Only added two items to the list and tried to update the second one)
It was found to be False (this explains why the values aren't actually
beeing updated in the list).

My Questions are:
1. Why doesn't it keep the reference, and making updates like such will
work?
2. Is there something wrong with my code?
3. Is there a WorkAround you know that might work?

Thanks alot...
 
SchedulerEvent is a Structure
^^^^^^^^^^

There's your problem. Since it's a structure (a value type), there are
no references involved. Copies of the value are passed around and
changing one doesn't affect other copies.


Mattias
 
Ok, I'm A Bit shocked... :)

Is there another Structure like type that can use references?

Thanks for the quick answer!
 
Forget my question... the answer is simple...
All i need to create is a class.... a seperate class for that type...

Thanks anyway!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top