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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:38:07+00:00 2026-06-05T07:38:07+00:00

Look at the code below and tell me why after calling the function UpdateContext,

  • 0

Look at the code below and tell me why after calling the function UpdateContext, the variable connection2 don’t have the same hashcode that variable connection1.

When I set the variable connection2 to connection1, both variables have a pointer to the same memory address. But after passing the variable connection1 by ref in the function UpdateContext that modify the pointer with the ‘new’ instruction, the connection1 have a new pointer address but the connection2 is still with the old address.

   class Program
   {
      static void Main(string[] args)
      {
         var connectionInitializer = new ConnectionInitializer();

         connectionInitializer.Initialize();

         Console.ReadLine();
      }
   }

   public class Connection
   {

   }

   public class ConnectionInitializer
   {
      public void Initialize()
      {
         var connection1 = new Connection();
         var connection2 = connection1;

         Console.WriteLine("Connection 1 (Before ref): " + connection1.GetHashCode());
         Console.WriteLine("Connection 2 (Before ref): " + connection2.GetHashCode());

         this.UpdateContext(ref connection1);

         Console.WriteLine("Connection 1 (After ref): " + connection1.GetHashCode());
         Console.WriteLine("Connection 2 (After ref): " + connection2.GetHashCode());
      }

      private void UpdateContext(ref Connection connection)
      {
         connection = new Connection();
      }
   }

Thank you for your help.

  • 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-05T07:38:08+00:00Added an answer on June 5, 2026 at 7:38 am

    connection2 still references the original Connection object. connection1 has been modified to refer to a new Connection object. connection1 and connection2 are not literally the same reference. connection2 is a copy of connection1 and both of these references, for a time, referred to the same object.

    These two references are not linked in any meaningful way aside from what they refer to, one is simply a copy of another. Changing the original will not reflect upon the copy.

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

Sidebar

Related Questions

Can you have a look at the code below and tell me how I
Please have a look at the code below: Class A package generalscenarios; public class
Please have a look at the code below: import string from collections import defaultdict
Please have a look on the code below .. <div id=click_me>Save</div> <div id=blocks_sortable> <div
Could you please have a look at my code below. #!C:\Perl\bin\perl.exe use strict; use
Quick question about jQuery and DOM traversal. Look at the code below and tell
Please have a look at the code below (excerpt from a C# book): public
Please have a look at the code below: - (NSArray *)requestEntities:(NSString *)entityName { NSFetchRequest
please look at the code below. class Program { static void Main(string[] args) {
Please take a look at the code snippet below. I want the 2nd MongoDB

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.