假設我有一類像如何確定一類具有實現特定接口或不
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();
有什麼辦法....請討論。謝謝。使用
好如果你需要知道這一點,推測在執行時你有* *東西*你有一個對象,或只是類型的名稱,或者是什麼? –
Erm看代碼或元數據類 –
@JonSkeet也許我錯了,但我認爲OP是問如何在設計時確定它。 –