update same object in multiple collections

  • Thread starter Thread starter njp
  • Start date Start date
N

njp

BlankHi,

How do I create a tightly coupled Object 1 such that when I update it in one collection, it is simultaneously and automatically updated in other collections? The collections are defined at the module level for the entire project to access as well as collections defined within different objects. Currently, I'm updating Object 1 manually in all the different collections but there surely must be a better way.

Thanks!
NJ
 
BlankIf you add the same object reference to all the collections, then making a change to a property of the object, through any of the references to it, causes those changes to appear when the object is referenced through any of the collections. You create a single object, on the heap, and the variable that gets a reference to is just that: a reference to the single instance of the object, residing on the heap.

This is true for classes, at any rate. Structs (Types in VB.Net) might not work the same way, since when you add a struct to a collection it's boxed, and consequently I believe that there will be separate copies of the struct on each of the separate collections. However, if you stick with classes it'll work the way you want.

Tom Dacon
Dacon Software Consulting

Hi,

How do I create a tightly coupled Object 1 such that when I update it in one collection, it is simultaneously and automatically updated in other collections? The collections are defined at the module level for the entire project to access as well as collections defined within different objects. Currently, I'm updating Object 1 manually in all the different collections but there surely must be a better way.

Thanks!
NJ
 
Back
Top