Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
class A { this() { } } class B : A { this() { } } auto b = new B() if(b.IsCastableTo(A)) { //... }
我将如何检查 b 是否可以转换为 A 类型?
根据 D 手册,您将执行以下操作:
if (cast(A) b) { // b is an instance of A } else { // b is not an instance of A }
参考: