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

  • Home
  • SEARCH
  • 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 908469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:43:23+00:00 2026-05-15T16:43:23+00:00

I want to have multiple objects share a reference through a private field, such

  • 0

I want to have multiple objects share a reference through a private field, such that any of the objects can assign to the field, and the updated field will be seen by other objects sharing that reference. What I was originally hoping to do was this:

class SomeObject
{
    private ref DataObject _data;
    public SomeObject(ref DataObject data)
    {
         _data = ref data; // or something similar
    }

    public ChangeData(DataObject newData)
    {
         _data = data;
         // at this point, *other* SomeObject instances that were
         // created with the same reference should also have _data == newData
    }
}

But of course you can’t use ref that way: ref is only for method parameters. And a static field won’t work, since not all SomeObject instances should refer to the same object—rather, the object in question should be set in the constructor.

Obviously I could solve this by just adding a simple wrapper class. But is there a better way? Is there some kind of SharedReference<T> class that I can use?

Update, since most of the answers misunderstood what I was asking. I know that the _data field contains a reference to the original DataObject. What I want is another level of indirection. I want to be able to change which object I’m pointing to in one instance, and have the new value be picked up by other instances that were created with the same reference. As the updated code sample shows, I want to assign to _data, and effectively change the value of _data in other instances.

  • 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-15T16:43:23+00:00Added an answer on May 15, 2026 at 4:43 pm

    I don’t know of any class that you can use for this, but I seems quite easy to implement your own SharedReference<T> class.

    Something like this:

    public sealed class SharedReference<T>
        where T : class
    {
        public T Reference
        {
            get; set;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 502k
  • Answers 502k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You want: questions that have answers questions that have a… May 16, 2026 at 2:32 pm
  • Editorial Team
    Editorial Team added an answer Is this on rails 3? If so, try calling "return… May 16, 2026 at 2:32 pm
  • Editorial Team
    Editorial Team added an answer your question "What would be the sql query to show… May 16, 2026 at 2:32 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have viewport3D and I want to add multiple 3d objects defined in xaml
What is the best way to share common objects between multiple views in an
I have read that HttpURLConnection supports persistent connections, so that a connection can be
I have an application that manages documents called Notes. Like a blog, Notes can
If I wanted to have Python distributed across multiple processors on multiple computers, what
I have a VB.NET application where various objects are going to access some common
I am not sure what the most appropriate way to handle JPA objects that
How do I handle selection of multiple items with autocomplete? The objects I return
I have multiple toggle buttons on my flash stage. These toggle buttons are MovieClips.
In a project that I've been involved with for many years, I've gradually evolved

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.