Creating instance of interface in C#

Posted by Max on Stack Overflow See other posts from Stack Overflow or by Max
Published on 2010-03-20T09:31:06Z Indexed on 2010/03/20 9:41 UTC
Read the original article Hit count: 140

Filed under:
|

I'm working with MS Excel interop in C# and I don't understand how this particular line of code works:

var excel = new Microsoft.Office.Interop.Excel.Application();

where Microsoft.Office.Interop.Excel.Application is an INTERFACE defined as:

[Guid("000208D5-0000-0000-C000-000000000046")]
[CoClass(typeof(ApplicationClass))]
public interface Application : _Application, AppEvents_Event
{
}

I'm thinking that some magic happens when the interface is decorated with a CoClass attribute, but still how is it possible that we can create an instance of an interface with a new keyword? Shouldn't it generate a compile time error?

© Stack Overflow or respective owner

Related posts about c#

Related posts about oop