title: Using real world units instead of types
body: <p>I have a project with many calculations involving a lot of real world units :</p>
  
  <ul>
  <li>Distance;</li>
  <li>Temperature;</li>
  <li>Flow rate;</li>
  <li>...</li>
  </ul>
  
  <p>This project involves complicated and numerous calculation formulas.</p>
  
  <p>That's why I supposed the use of custom types like <em>Temperature</em>, <em>Distance</em>... can be good for code readability. For example:</p>
  
  <pre><code>Temperature x = -55.3;
  Meter y = 3;
  </code></pre>
  
  <p>or</p>
  
  <pre><code>var x = new Temperature(-55.3);
  </code></pre>
  
  <p>I tried to make a Temperature class that uses a double internal value.</p>
  
  <pre><code>public class Temperature
  {
      double _Value = double.NaN;
  
      public Temperature() { }
  
      public Temperature(double v) {
          _Value = v;
      }
  
      public static implicit operator Temperature(double v) {
          return new Temperature(v);
      }
  }
  </code></pre>
  
  <p>But class are nullable. This mean that something like :</p>
  
  <pre><code>Temperature myTemp;
  </code></pre>
  
  <p>is "correct" and will be null. I dont want this. I dont want to use structs because they are too limited :</p>
  
  <ul>
  <li>They cannot use parameterless constructor nor instance field intializers like <code>double _Value = double.Nan;</code> to define a default value (I wand default underlying double value to be NaN)</li>
  <li>They cannot inherits from classes, they only can implement Interfaces</li>
  </ul>
  
  <p>Them I wonder whether there is a way to tell C#:</p>
  
  <pre><code>Temperature myTemp = 23K; // C# does not implement anything to make K unit...
  </code></pre>
  
  <p>but I know C# does not handle no custom units.</p>
  
  <pre><code>Temperature myTemp = new Kelvin(23); // This might work
  </code></pre>
  
  <p>So I imagine I could create two Celsius and Kelvin classes that inherits from Temperature, and then I started to wonder if the idea really worth it, because it involves a lot of coding and testing.</p>
  
  <p>That's the discussion I would like to start :</p>
  
  <p>Would the use of real world units in my code instead of .NET types would be a good thing or not ? Did anyone this already ? What are the pitfalls and the best practices ? Or should I better keep stay away from this and use standard .NET types ?</p>