title: C# Explicit Operators and Inheritance
body: <p>I'm sure this is a stupid question, but why does the following code not call the explicit operator for the cast on the child class MyBool?</p>
  
  <pre><code>public class DataType
  {
      public static explicit operator bool(DataType D)
      {
          return false;
      }
  
      public static explicit operator DataType(bool B)
      {
          return new DataType();
      }
  }
  
  public class MyBool : DataType
  {
      public bool Value;
  
      public MyBool()
      {
          Value = false;
      }
  
      public static explicit operator bool(MyBool B)
      {
          return B.Value;
      }
  
      public static explicit operator MyBool(bool B)
      {
          return new MyBool() { Value = B };
      }
  }
  </code></pre>
  
  <p>then:</p>
  
  <pre><code>List&lt;DataType&gt; Types = new List&lt;DataType&gt;();
  
  Types.Add(new MyBool() { Value = true });
  Types.Add(new MyBool() { Value = false });
  
  foreach (DataType T in Types)
  {
      bool Value = (bool)T;
      MessageBox.Show(Value.ToString());
  }
  </code></pre>
  
  <p>Produces the output: false, false</p>
  
  <p>Is my only option to write functions on each class to take the place of the explicit operator functions?</p>