473,769 Members | 4,591 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2064
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.c om> wrote in message news:eM******** ******@tk2msftn gp13.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****@communi ty.nospam> wrote in message news:ui******** *****@TK2MSFTNG P11.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.c om> wrote in message news:eM******** ******@tk2msftn gp13.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
1259
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. (I'll use lazy init to fill the collections when needed.) More specialized employee types would inherit from the base class. Sometimes, though, all I need is the employee name and ID number - for example, when filling a DDL - and I hate to...
1
2994
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 problem come up when I want to delete one of rows in datagrid and update the change to the corresponding table. The error msg show up "Dynamic SQL generation is not supported against multiple base tables."
5
8303
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 not working. The Address column is DataType NVarChar 90, no problem. Any idea?
3
2541
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 Object, it throws a cast error. The only way I've been able to get this to work is to return an ArrayList and then use the .CopyTo method of the ArrayList to stuff the ArrayList into my array. I've tried DirectCast and several other methods to get...
1
276
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 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
5
3850
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 to the object has occurred correctly; have I got a foobar somewhere, or is this the expected behaviour? I can "fix" it by adding an additional few lines (follows main code), but this is ugly; any ideas? And can I get a robust MVP-style UI in a...
8
5370
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 this code there is a panel panel1, that I populate with a lable in the foreground. Then when I click on "button1" a backgroundworker thread in async mode is started. When the backgoundworker thread completes the thread returns a panel to populate...
6
6917
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 user actions, I want to create n number instances of those classes, which is obviously unknown at compile time. What is the easiest way to create and then manage these kinds of objects? Using an array seems intuitive but it also seems like it...
5
1793
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 risk of losing some new entries, so I've deceided to create an update thread. This thread is created when the program's start and should (for various reason) run not in sync with the Filemonitor. The Filemonitor event creates an entry in a...
0
10223
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10000
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9866
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8879
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3968
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3571
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.