title: Equivalent of C++'s reinterpret_cast in C#
body: <p>I wonder what's the equivalent of C++'s <code>reinterpret_cast</code> in C#!?</p>
  
  <p>Here's my sample:</p>
  
  <pre><code>class Base
  {
      protected int counter = 0;
  }
  
  class Foo : Base
  {
      public int Counter
      {
          get { return counter; }
      }
  }
  
  Base b = new Base();
  Foo f = b as Foo; // f will be null
  </code></pre>
  
  <p>I've got no objection why <code>f</code> will be null since it should be. But if it was C++ I could have written <code>Foo f = reinterpret_cast&lt;Foo&gt;(b);</code> and get what I wanted. What can I do to achieve the same in C#?</p>
  
  <p><strong>PS. I'm assuming that <code>Base</code> and <code>Foo</code> are consistent data-wise.</strong></p>
  
  <p><strong>[UPDATE]</strong></p>
  
  <p>Here's a simple scenario where a <code>reinterpret_cast</code> could be helpful:</p>
  
  <p>Consider writing an XXX-RPC library where you've got no control over the incoming parameters nor the signature of services to call. Your library is supposed to call the asked service with the given parameters. If C# supported <code>reinterpret_cast</code> I could simply <code>reinterpret_cast</code> the given parameters into the expected ones and call the service.</p>