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 6582841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:19:54+00:00 2026-05-25T16:19:54+00:00

I have: instance1 = instance2; how do I disconnect them from one another, so

  • 0

I have:

instance1 = instance2;

how do I disconnect them from one another, so that altering one will not affect the other?

EDIT: I want them referencing the same object (so I can’t clone), and later – not. But I still want both instances of the class – so I can’t ‘null’ them.

Thanks

EDIT:

myclass a = new myclass();
a.integer = 1;

myclass b = new myclass();
b.integer = 2;

a = b;
//All changes to one will affect the other, Which is what I want.



//<More lines of the program>



//Now I want 'a' to point to something else than 'b'. and I’m missing the code
//so that the next line will not affect 'b'.
a.integer = 1;

Text = b.integer.ToString();
//I need b.integer to still be = 2, it’s not.

With:

class myclass
{
    public int integer;
}

EDIT:

This is the answer:
@ispiro but when you say a.integer = 1 you aren’t changing the pointer, you are following the pointer and changing the value at the end of it. – Davy8

I had thought that changing both ‘a’ and ‘a.integer’ would be the same in the sense that changing them would either change pointer-‘a’ or won’t. But in fact: the first does, the second doesn’t.

Thanks everyone.

So in the example above, if I add:

a = c;// where c is another instance of 'myclass'.

It will change ‘a’ to point somewhere else than ‘b’.
But:

a.integer = 1;

did not.

  • 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-25T16:19:55+00:00Added an answer on May 25, 2026 at 4:19 pm

    Your code:

    myclass a = new myclass();
    a.integer = 1;
    
    myclass b = new myclass();
    b.integer = 2;
    
    a = b;
    
    //here I need code to disconnect them
    
    a.integer = 1;
    
    Text = b.integer.ToString();
    //I need b.integer to still be = 2
    

    enter image description here

    If you keep around a reference:

    myclass a = new myclass();
    a.integer = 1;
    
    myclass b = new myclass();
    b.integer = 2;
    
    var c = a; //Keep the old a around
    a = b;
    
    //here I need code to disconnect them
    a = c; //Restore it.
    
    a.integer = 1;
    
    Text = b.integer.ToString();
    //It's still 2 now.
    

    enter image description here

    Variables are labels to the objects, not the objects themselves. In your case, the original a no longer has a reference to it so even though it exists, there’s no way to access it. (and it’ll cease to exist whenever the garbage collector gets around to getting rid of it unless there are other references to it)

    If it helps, think of it this way, when you say a = b or a = new myclass() you are moving the line where a is pointing. When you say a.integer = 1, the . is kind of like saying follow the line a is pointing to, then change the destination.

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

Sidebar

Related Questions

I have a class ( MyClass ) that inherits most of its functionality from
I have several instances where that a section of legacy sql statements is based
I have an instance of a UITableView, and a separate class that adheres to
I have an instance of Class A that I want to refer to in
I have a mod_perl2 based web app that requires a connection to a mysql
I have an application that needs to constantly (every 50ms), call to an MVC
I have a 3rd party DLL that needs to be loaded dynamically using LoadLibrary()
I have a use case where a servlet (that has reasonably high concurrent use)
In my code, I have a class that maintains a number of lists. We'll
I have been given the task of bringing three legacy systems together into one

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.