Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4270920
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:22:19+00:00 2026-05-21T07:22:19+00:00

I have some Foo objects which are contained in Bar objects: class Foo {

  • 0

I have some Foo objects which are contained in Bar objects:

class Foo
{
    int uniqueId; // every Foo has a different ID.
    List<int> data;
}

class Bar
{
    Foo foo = new Foo();
}

Sometimes I want to merge the Foo objects that belong to different Bars as follows:

public void MergeWith(Bar otherBar)
{
    this.foo.uniqueId = otherbar.foo.uniqueId;
    this.foo.data.AddRange(otherbar.foo.data);     

    otherBar.foo = this.foo;
    // Now both Bar objects refer to the same Foo, which contains all the data.
}
Bar bar1;
Bar bar2;
bar1.MergeWith(bar2);

This is fine. The problem is that these Bar objects have handed out a references to their Foo objects to Baz objects. Baz has a List<Foo> it’s collected from multiple sources.

How can I get the Baz objects to know when their Foos are outdated? Should the Foo objects have a reference to their “newer” Foo, linked list style? Or is there a better way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T07:22:20+00:00Added an answer on May 21, 2026 at 7:22 am

    I can only think of two ways that early in the morning:

    • Do not hand out a reference always
      use a property to return the current
      reference
    • Implement a OnFooChange
      event and post the change to all
      parties interested from within the Bar class/ instance

    hth

    Mario

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a linked list of Foo objects. Foo is a base class, which
I have a class Foo, which has a (simple) destructor. Some other class contains
So i have some code like this: void foo (int, int); void bar (
I have a class Foo that uses another class Bar to do some stuff.
I have a generic List (of Foo) which contains n objects of Type Foo.
My situation is essentially this: I have a class called Foo which has dependencies
I have a UIManagedDocument with some data which I display in a list using
Lets suppose that I have some pages some.web/articles/details/5 some.web/users/info/bob some.web/foo/bar/7 that can call a
I have some third-party Javascript that has statements like this: FOO = function() {
I have a bunch of code of the form: someVector.push_back(Foo(some name, 1.0, 3.1415926); someVector.push_back(Foo(different

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.