Mak*_*ach 5 c# inheritance types
鉴于这种情况
interface A {}
class B : A {}
A b = new B();
Run Code Online (Sandbox Code Playgroud)
如何检查对象b是否从界面A创建?
你可以像这样测试它:
var b = new B();
var asInterface = x as A;
if (asInterface == null)
{
//not of the interface A!
}
Run Code Online (Sandbox Code Playgroud)