|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Using Find method on a List(of type) Breaks the ReferenceI 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 -- Mattias Sjögren [C# MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup. 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!
MS's Excruciating Update Cycles
Datagrid with VB 2005 My computer seems to be to slow to run VS2005 Translation of CreateFile dll in dot net Late Binding Question large arrays and system.outofmemoryexception DataBinding and Combo Boxes Is it possible to use Field Names instead of Item(0) with Data Row using VB.Net 2005 ? Web Panel? XML into datagrid |
|||||||||||||||||||||||