title: C# Class with dependent properties
body: <p>I'm very new to C# programming, and I'm currently struggling with what should be (I think) a piece of cake code for experienced programmers.
  I want to write a very little app to calculate a tax (21%) on a number:</p>
  <ul>
  <li>If I define an exclVAT number, it should return the calculated inclVAT number</li>
  <li>If I define an inclVAT number, it should return the calculated exclVAT number</li>
  </ul>
  <p>My goal is to have something like this: an app that gives the results as soon as you type a value in one of the two boxes:</p>
  <p><a href="https://i.stack.imgur.com/4DWbJ.png" rel="nofollow noreferrer">VAT utility</a>
  (This will be done in WPF using XAML, with an INotifyPropertyChanged interface, but this is not the goal of my question).</p>
  <p>I'm trying to do this with 1 class, and 2 properties: inclVat and exclVat (both as type double). But the tricky thing is that both properties depend on each other.
  So if I set/change the exclVat property to 100, I want to have the inclVat property to be changed to 121. And if I set/change the inclVat value to 100, I want the exclVat property changed to 0,83.</p>
  <p>I already come up with this code, but is is not sufficient, as the public property fields don't change when I change the values on them...</p>
  <p>The Class:</p>
  <pre><code>public class Vat
      {
  
          private double _inclVat;
  
          public double InclVat
          {
              get 
              {
                  if (_ExclVat == 0)
                  {
                      return _inclVat;
                  }
                  else
                  {
                      return (_ExclVat * 1.21);
                  }
                  
              }
              set
              {
                  _inclVat = value;
              }
          }
  
          private double _ExclVat;
  
          public double ExclVat
          {
              get 
              {
                      return System.Math.Round(_inclVat / 1.21, 2);
              }
              set
              {
                  _ExclVat = value;
                  
              }
          }
      }
  </code></pre>
  <p>And when I run it with some assignments:</p>
  <pre><code>Vat Number = new Vat();
  Number.InclVat = 100;
  
  System.Console.WriteLine($&quot;InclVat: {Number.InclVat}&quot;);
  System.Console.WriteLine($&quot;ExclVat: {Number.ExclVat}&quot;);
  
  System.Console.WriteLine(&quot;Changing inclVat to 200&quot;);
  Number.InclVat = 200;
  
  System.Console.WriteLine($&quot;InclVat: {Number.InclVat}&quot;);
  System.Console.WriteLine($&quot;ExclVat: {Number.ExclVat}&quot;);
  
  System.Console.WriteLine(&quot;Changing exclVat to 100&quot;);
  Number.ExclVat = 100;
  
  System.Console.WriteLine($&quot;InclVat: {Number.InclVat}&quot;);
  System.Console.WriteLine($&quot;ExclVat: {Number.ExclVat}&quot;);
  </code></pre>
  <p>I have the following output:</p>
  <pre><code>InclVat: 100
  ExclVat: 82,64
  Changing inclVat to 200
  InclVat: 200
  ExclVat: 165,29
  Changing exclVat to 100
  InclVat: 121
  ExclVat: 165,29
  </code></pre>
  <p>In the beginning it's ok, but as soon as I change the exclVat property, the output isn't ok anymore (last 2 lines).
  Can anyone help me with this?</p>