Tag: reinterpret cast

在C#中等效C ++的reinterpret_cast

我想知道在C#中C ++的reinterpret_cast相当于什么? 这是我的样本: 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 我没有异议为什么f应该是null,因为它应该是。 但如果它是C ++我可以写Foo f = reinterpret_cast(b); 得到我想要的东西。 我能做些什么来在C#中实现同样的目标? PS。 我假设Base和Foo在数据方面是一致的。 [UPDATE] […]