title: C# Instance copy / Passing object reference is different then Java?
body: <pre><code>class Player
  {
     private Location location;
  
     public Location getLocation()
     {
          return location;
     }
  
      public void setLocation(Location location)
      {
          this.location = location;
      }
  }
  </code></pre>
  
  <p>...</p>
  
  <pre><code>class Location
  {
      int x,y,z;
  
      public Location(int x, int y, int z)
      {
          this.x = x;
          this.y = y;
          this.z = z;
      }
  
      public Location(Location location)
      {
          this.x = location.x;
          this.y = location.y;
          this.z = location.z;
      }
  
  
      public void updateLocation(Location location) //the fix..
      {
          this.x = location.x;
          this.y = location.y;
          this.z = location.z;
      }
  }
  </code></pre>
  
  <p>Say.. you do</p>
  
  <pre><code>Player p1 = new Player();
  Player p2 = new Player();
  p1.setLocation(p2.getLocation());
  </code></pre>
  
  <p>Now the bug/problem occurs when you attempt to modify other persons location. Both players locations changes exactly the same, as they both now share the same location.</p>
  
  <p>So of course this below will work just fine.</p>
  
  <pre><code>p1.setLocation(new Location(p2.getLocation()));
  </code></pre>
  
  <p>but the problem is it always creates a new object.. when I could just update the existing instance..? how do I update the existing instance on default without making my own methods like I did below to fix this.</p>
  
  <p>I had to fix this using the method below (any way to do this by default without doing like this below)</p>
  
  <pre><code>    public void setLocation(Location location)
      {
          if (this.location == null)
              this.location= new Location(location);
          else
              this.location.updateLocation(location);
      }
  </code></pre>
  
  <p>Anyone knows any tricks I may not know about? Thanks.</p>