It’s not what you do, but the way that you do it

Take a simple few lines of C#.

void Main()
A foo = new A();

If it compiles, then it can’t fail at runtime, right?

C# has got some extensions to make it "easier" to deal with legacy COM components (though I’m not sure I believe that). If an interface is marked with appropriate attributes then you’re allowed to use new on the interface type and the compiler will, behind the scenes, transform this instantiation into a construction of another class. The compiler has no problem with this class being unrelated to the interface that we started with.


public interface A

public class Test


There’s some discussion of this here on Stack Overflow.


This entry was posted in Computers and Internet. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s