title: C# Struct method doesn't save value if accessed by a property
body: <p>I need to create a structure that looks like an int (but has an extra field that I need...), so I created a new structure named TestStruct added one method (test()) that I needed and overloaded some operators, and it seemed to be working well...</p>
  
  <p>The sample below shows the problem. If the structure test() method is executed from the Val property then the Val property seems to lose the value, but if the method is executed on the Val2 variable, this one seems to keep the right value...</p>
  
  <p>Why does this happen?</p>
  
  <pre><code>static class Program
  {
      /// &lt;summary&gt;
      /// The main entry point for the application.
      /// &lt;/summary&gt;
      [STAThread]
      static void Main()
      {
          new TestClass();
      }
  }
  
  public class TestClass
  {
      public TestStruct Val { get; set; }
      private TestStruct Val2;
  
      public TestClass()
      {
          Val.test();
          Console.WriteLine(Val + "-&gt; why is it not 10?");
  
          //Direct assignment works well...
          Val = 123;
          Console.WriteLine(Val  + "-&gt; direct assingment works..");
  
          //This way works too. Why doesn't it work with "get;" and "set;"?
          Val2.test();
          Console.WriteLine(Val2 + "-&gt; it works this way");
      }
  }
  
  public struct TestStruct
  {
      private Int32 _Value;
      public long Offset { get; set; }
  
      public static implicit operator TestStruct(Int32 value)
      {
          return new TestStruct { _Value = value };
      }
  
      public static implicit operator Int32(TestStruct value)
      {
          return value._Value;
      }
  
      public void test()
      {
          _Value = 10;
      }
  }
  </code></pre>