title: Is it possible to have two variables point to the same memory address in C#?
body: <p>So I'm playing around with C# right now, coming from the world of C++.</p>
  
  <p>I'm trying to make two object variables point to the SAME memory address, in a way that if I edit variable 1, variable 2 is also being changed.</p>
  
  <p>Is this possible?</p>
  
  <p>Reason I'm asking is because I would ideally like to have an instance of an object inside of one object, and then also inside of a different type of object. So that if the value is changed in one object, it changes in both. Like this (or at least something like this).</p>
  
  <pre><code>public class Demo
  {
      public int x;
  }
  
  public class DemoContainer1
  {
      public DemoContainer1(ref Demo new_demo)
      {
          demo = new_demo;
      }
  
      public int SetX(int x)
      {
          demo.x = x;
      }
  
      private Demo demo;
  }
  
  public class DemoContainer2
  {
      public DemoContainer2(ref Demo new_demo)
      {
          demo = new_demo;
      }
  
      private Demo demo;
  }
  
  Demo new_demo = new Demo();
  new_demo.x = 5;
  
  DemoContainer1 container1 = new DemoContainer1(ref new_demo);
  DemoContainer2 container2 = new DemoContainer2(ref new_demo);
  
  container1.SetX(10);
  
  // The following should now be true... container1.demo.x == 10 AND container2.demo.x == 10
  </code></pre>