Quiz: Instantiating an interface

I got this one from a reader down under… I gotta say, it pretty much had me stumped, so I thought I’d share it with you…

Compile the following code and you get this error message:

Cannot create an instance of the abstract class or interface 'IFoo'

interface IFoo { }

public class Class1

{

    static void Main()

    {

        new IFoo();

    }

}

Of course you say, you can never create an instance of an interface, only an instance of a concrete class that implements an interface. It says so right in the error message.

Well, not so. Your quiz today is to only add lines above and below the code snippet above to make it compile cleanly. (No comments or #define magic here please).