Let's say you define some arbitrary interface:
public interface IInterface {
void SomeMethod();
}
And let's say there are some classes that happen to have a matching public interface, even though they do not "implement IInterface
". IE:
public class SomeClass {
public void SomeMethod() {
// some code
}
}
Is there nevertheless a way to get an IInterface
reference to a SomeClass
instance? IE:
SomeClass myInstance = new SomeClass();
IInterface myInterfaceReference = (IInterface)myInstance;