title: C# and Data Hiding
body: <p>I'm new to C# and .Net in general so this may be a naive thing to ask. But anyway, consider this C# code:</p>
  
  <pre><code>class A {
      public int Data {get; set;}
  }
  
  class B {
      public A Aval {get; set;}
  }
  </code></pre>
  
  <p>The B.Aval property above is returning a reference to its internal A object. As a former C++ programmer, I find this dangerous because by exposing reference to an member object class B violates the principle of data hiding. Nonetheless, this seems to be the normal practice in the C# world.</p>
  
  <p>My question is, if it is at all, why is such a design the usual approach as opposed to returning copies of internal members, which will be much safer in so many ways (including the case of thread safety)?</p>
  
  <p>I understand that even in C++ sometimes good design demands that you do expose class members directly (a <strong>Car</strong> class with <strong>Engine</strong> and <strong>Stereo</strong> objects inside it comes to mind), but it is not the norm as seems to be in C#.</p>