title: Why is my internal field getting modified - understanding how C# references objects
body: <p>I have something similar to the following very simple code, but I'm getting caught out by the way objects are referenced. I'd like to understand what's going on a little more.</p>
  
  <p>I'm surprised to find that _connection.Name and _connection.Enabled can be modified outside of the class.</p>
  
  <pre><code>internal class ConnectionProperties
  {
      internal string Name = "Default Name";
      internal bool Enabled = true;
  }
  
  internal class Data
  {
      private readonly ConnectionProperties _connection;
      internal string ConnectioName =&gt; _connection.Name;
  
      internal ConnectionProperties Connection()
      {
          return _connection;
      }
  
      internal Data()
      {
          this._connection = new ConnectionProperties();
      }
  
  }
  
  
  class Program
  {
      static void Main(string[] args)
      {
          Data data = new Data();
  
          Console.WriteLine(data.ConnectioName);
  
          ConnectionProperties temp = data.Connection();
          temp.Name = "New Name";
  
          Console.WriteLine(data.ConnectioName);
  
      }
  }
  </code></pre>
  
  <blockquote>
    <p>OUTPUT:</p>
    
    <p>Default </p>
    
    <p>Name New Name</p>
  </blockquote>