title: Compile-time and runtime casting c#
body: <p>I was wondering why some casts in C# are checked at compile-time whereas in other cases the responsibility is dumped on CLR. Like above both are incorrect but handled in a different way.</p>
  
  <pre><code>class Base { }
  class Derived : Base { }
  class Other { }
  
  static void Main(string[] args)
  {
      Derived d = (Derived)new Base();     //Runtime       InvalidCastException
      Derived d = (Derived)new Other();    //Compile-time  Cannot convert type...
  }
  </code></pre>
  
  <p>While reading <em>"C# in depth"</em> I've found the information on this topic where autor says:<br>
    <em>"If the compiler spots that it’s actually impossible for that cast to work, it’ll trigger a compilation error—and if it’s theoretically allowed but actually incorrect at execution time, the CLR will throw an exception."</em></p>
  
  <p>Does 'theoretically' mean connected by inheritance hierarchy (some another affinity between objects ?) or it is compiler's internal business? </p>