title: C# getters/setters in structs and interfaces
body: <p>I came along an (according to me) strange difference between structs and interfaces in C#. Consider this interface and struct: </p>
  
  <pre><code>public interface INumber
  {
      void ChangeNumber(int n);
      void Log();
  }
  public struct Number : INumber
  {
      private int n;
      public void ChangeNumber(int n)
      {
          this.n = n;
      }
      public void Log()
      {
          Console.WriteLine(this.n);
      }
  }
  </code></pre>
  
  <p>When I create a new class with a Number as property, use the ChangeNumber method to change n to 2 and print the number by using Log, it prints 0 instead:</p>
  
  <pre><code>public class NumberContainer
  {
      public Number Number { get; set; }
      public NumberContainer()
      {
          this.Number = new Number();
          this.Number.ChangeNumber(2);
          this.Number.Log();              //prints 0...
      }
  }
  </code></pre>
  
  <p>After a while I realised it was because when I call <code>this.Number.ChangeNumber(2);</code>, I actually create a new object (because of the getter) and change that number to 2. But then I changed a little bit of the code by changing the Number property to an INumber property: </p>
  
  <pre><code>public class NumberContainer
  {
      public INumber Number { get; set; }
      public NumberContainer()
      {
          this.Number = new Number();
          this.Number.ChangeNumber(2);
          this.Number.Log();              //prints 2!
      }
  }
  </code></pre>
  
  <p>In this case, it prints 2! Why is this happening? Doesn't the same principal of structs apply to the interface?</p>