Given this scenario
interface A {}
class B : A {}
A b = new B();
How can I check that object b is created from interface A?
Given this scenario
interface A {}
class B : A {}
A b = new B();
How can I check that object b is created from interface A?
You could do test it like this:
var b = new B();
var asInterface = x as A;
if (asInterface == null)
{
//not of the interface A!
}
We found it practical to use the following:
IMyInterface = instance as IMyInterface;
if (intance != null)
{
//do stuff
}
'as' is the faster than 'is', also is saves a number of casts - if your instance impelments IMyInterface, you'll need no more casts.