By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,534 Members | 910 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,534 IT Pros & Developers. It's quick & easy.

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

P: n/a

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
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
2. Is there something wrong with my code?
3. Is there a WorkAround you know that might work?

Thanks alot...

Mar 29 '06 #1
Share this Question
Share on Google+
3 Replies

P: n/a
>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 Sjögren [C# MVP] mattias @ |
Please reply only to the newsgroup.
Mar 29 '06 #2

P: n/a
Ok, I'm A Bit shocked... :)

Is there another Structure like type that can use references?

Thanks for the quick answer!

Mar 29 '06 #3

P: n/a
Forget my question... the answer is simple...
All i need to create is a class.... a seperate class for that type...

Thanks anyway!

Mar 29 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.