Suppose I have a class like
interface ISampleInterface
{
void SampleMethod();
}
class ImplementationClass : ISampleInterface
{
// Explicit interface member implementation:
void ISampleInterface.SampleMethod()
{
// Method implementation.
}
static void Main()
{
// Declare an interface instance.
ISampleInterface obj = new ImplementationClass();
// Call the member.
obj.SampleMethod();
}
}
在编写以下代码之前,我如何确定 ImplementationClass
类实现了 ISampleInterface
接口?
SampleInterface obj = new ImplementationClass();
obj.SampleMethod();
有没有方法...请讨论。谢谢。
SampleInterface obj = new ImplementationClass();
之前”意味着他没有对象实例,并希望对类型进行测试。 - Olivier Jacot-Descombes