473,387 Members | 1,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

update same object in multiple collections

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
Jul 21 '05 #1
2 2020
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

"njp" <np***@systek.com> wrote in message news:eM**************@tk2msftngp13.phx.gbl...
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
Jul 21 '05 #2
njp
BlankThanks Tom, this helps!

"Tom Dacon" <td****@community.nospam> wrote in message news:ui*************@TK2MSFTNGP11.phx.gbl...
If 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

"njp" <np***@systek.com> wrote in message news:eM**************@tk2msftngp13.phx.gbl...
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
Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Roger Bonine | last post by:
I'm working on a rewrite of our employee database. I plan to implement a fairly heavyweight base class, which includes 20 or 30 fields, including address and phone number collections and the like....
1
by: Wing | last post by:
Hi all, I have created 2 tables in sql database and join these 2 tables before assign the result to the dataset, and display the result in datagrid. Everything is fine up to this point. The...
5
by: Jason Huang | last post by:
Hi, The SqlParameter myPM =new SqlParameter("@Address", txtAddress.Text) is working for update, but SqlParameter myPM =new SqlParameter ("@Address",SqlDbType.NVarChar,90,txtAddress.Text) is...
3
by: Stephen Travis | last post by:
I'm trying to write a subroutine that will fill an array of some type with several objects of that type. The subroutine works fine if I directly reference the array but if I pass the array as an...
1
by: njp | last post by:
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...
5
by: Marc Gravell | last post by:
In the following example, the Bindings don't update the UI if the property change is triggered from the non-UI thread - see the async button - from the listbox contents (and observation) the change...
8
by: =?Utf-8?B?R3JlZyBMYXJzZW4=?= | last post by:
I'm trying to figure out how to modify a panel (panel1) from a backgroundworker thread. But can't get the panel to show the new controls added by the backgroundwork task. Here is my code. In...
6
by: Bugs | last post by:
Does anyone have any recommendations on the best way to create multiple instances of the same class when the final number of instances is unknown? For example, I have a class and based on some...
5
by: P.J.M. Beker | last post by:
Hi there, I'm currently writing a program in which I use the FileMonitor to monitor a folder in which I store downloaded images. I know that I can't add much coding in the filemonitor's event in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.