Here's one I only found out about recently...
interface IFoo
{
string Message {get;}
}
...
IFoo obj = new IFoo("abc");
Console.WriteLine(obj.Message);
The above looks crazy at first glance, but is actually legal.No, really (although I've missed out a key part, but it isn't anything hacky like "add a class called IFoo
" or "add a using
alias to point IFoo
at a class").
See if you can figure out why, then: Who says you can’t instantiate an interface?