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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:21:52+00:00 2026-06-12T09:21:52+00:00

I keep wanting to know if two variables are pointing at the same instance

  • 0

I keep wanting to know if two variables are pointing at the same instance of a class. Sounds obvious, but can it be done?

For example. Imagine you have the following code with an operator called “IsSameInstanceAs”. Is there any way of fulfilling the logic of the “IsSameInstanceAs” operator as stated in the comments inside the if statements using .Net, C#:-

public class MyClass
{
    public String MyString;

    public static void TestForSameInstance()
    {
        MyClass myInstanceA = new MyClass();
        MyClass myInstanceB = myInstanceA;
        MyClass myInstanceC = new MyClass();

        myInstanceA.MyString = "A String";
        myInstanceC.MyString = myInstanceA.MyString;

        if (myInstanceA IsSameInstanceAs myInstanceB)
        {
            // These are the same instance so they will match and this if is true
        }

        if (myInstanceA IsSameInstanceAs myInstanceC)
        {
            // These are not the same instance so they will not match and this if is false
        }
    }
}

I believe this cannot be done, but if anyone knows better then please help. Remember, I do not want to compare object instances, I want to know if they are the same instance.

John Thompson

  • 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-06-12T09:21:52+00:00Added an answer on June 12, 2026 at 9:21 am

    Object.ReferenceEquals is the relevant method.

    Determines whether the specified Object instances are the same
    instance.

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

Sidebar

Related Questions

(Keep in mind this is on OSX Snow Leopard) I don't know how to
Keep going around circles, but I am still unclear about this. Have a feeling
I keep getting an error saying that @android:style/Widget.Holo.Light.Button.Borderless is not public and so can't
I'm wanting to detect all objects(classes) defined in a php file (example: flavors.php). The
This question is plain ignorance, sorry. I can't find the example I want. If
I'm setting up a CI for our development and wanting to know ideas/best practices
I'm wanting to compile MySQL into a user-specific directory on my Mac. I know
Keep running into When using the multi-mapping APIs ensure you set the splitOn param
Keep getting this error after inserting a subdatasheet into a query and trying to
Keep getting the error Arguments are not sufficiently instantiated for the multiplication by addition

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.