<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Quiz: Instantiating an interface</title><link>http://blogs.msdn.com/brada/archive/2004/10/10/240523.aspx</link><description>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</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Quiz: Instantiating an interface</title><link>http://blogs.msdn.com/brada/archive/2004/10/10/240523.aspx#240535</link><pubDate>Mon, 11 Oct 2004 00:12:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:240535</guid><dc:creator>Roy Osherove</dc:creator><description>does this count? (it compiles alright)&lt;br&gt;	interface IFoo&lt;br&gt;	{&lt;br&gt;			 &lt;br&gt;	}&lt;br&gt;&lt;br&gt;	public class Class1&lt;br&gt;	{&lt;br&gt;		static void Main()&lt;br&gt;		{&lt;br&gt;			new IFoo();&lt;br&gt;		}&lt;br&gt;		&lt;br&gt;		class IFoo&lt;br&gt;		{&lt;br&gt;&lt;br&gt;		}&lt;br&gt;&lt;br&gt;	}&lt;br&gt; </description></item><item><title>re: Quiz: Instantiating an interface</title><link>http://blogs.msdn.com/brada/archive/2004/10/10/240523.aspx#240581</link><pubDate>Mon, 11 Oct 2004 03:06:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:240581</guid><dc:creator>Kris</dc:creator><description>I came up with the same thing... an inner class within Class1 and it compiles fine.  </description></item><item><title>re: Quiz: Instantiating an interface</title><link>http://blogs.msdn.com/brada/archive/2004/10/10/240523.aspx#240585</link><pubDate>Mon, 11 Oct 2004 03:18:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:240585</guid><dc:creator>David James</dc:creator><description>In the original quiz, IFoo was already a private nested interface, so no, it doesn't count :-)&lt;br&gt;&lt;br&gt;(I sent the quiz around the office, and one of my colleagues forwarded it to Brad, but I guess it mutated along the way.)</description></item><item><title>re: Quiz: Instantiating an interface</title><link>http://blogs.msdn.com/brada/archive/2004/10/10/240523.aspx#240595</link><pubDate>Mon, 11 Oct 2004 03:59:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:240595</guid><dc:creator>Kevin Dente</dc:creator><description>Compile, you say? This will make it compile:&lt;br&gt;&lt;br&gt;    [System.Runtime.InteropServices.ComImport()]&lt;br&gt;    [System.Runtime.InteropServices.Guid(&amp;quot;D95FCCE0-F518-46c4-87CA-D9FCED7223A1&amp;quot;)]&lt;br&gt;    [System.Runtime.InteropServices.CoClass(typeof(Class1))]&lt;br&gt;    interface IFoo { }&lt;br&gt;&lt;br&gt;But I'm not sure if that's what you're looking for...</description></item><item><title>re: Quiz: Instantiating an interface</title><link>http://blogs.msdn.com/brada/archive/2004/10/10/240523.aspx#240607</link><pubDate>Mon, 11 Oct 2004 04:26:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:240607</guid><dc:creator>Judah Himango</dc:creator><description>Stumped! Looked at this one for 10 minutes and best I could come up with was a nested class named IFoo, but David says this isn't allowed. Looking forward to seeing the solution! :-)</description></item><item><title>re: Quiz: Instantiating an interface</title><link>http://blogs.msdn.com/brada/archive/2004/10/10/240523.aspx#240636</link><pubDate>Mon, 11 Oct 2004 06:07:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:240636</guid><dc:creator>Wilco Bauwer</dc:creator><description>Kevin is right. This topic is most likely about &amp;quot;class interfaces&amp;quot;.  Whenever you import an object with the type library importer, those class interfaces (RCW) are generated (together with a class which's name is suffixed with 'Class' (also RCW)).&lt;br&gt;&lt;br&gt;(There are exceptions though, when objects for example only implement interfaces like IUnknown or IDispatch. They are never exposed as RCW classes because the members are internally called by the .NET framework.)</description></item><item><title>re: Quiz: Instantiating an interface</title><link>http://blogs.msdn.com/brada/archive/2004/10/10/240523.aspx#240739</link><pubDate>Mon, 11 Oct 2004 13:26:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:240739</guid><dc:creator>Jeff Parker</dc:creator><description>You can't instantiate an interface it must have a specific method, this is from my understanding, but you can new up the specific class that implements the interface and return it.&lt;br&gt;&lt;br&gt;I guess I would want to know more as to the reason to have a new interface that isn't implemented and has no code in it but the following would be usefull as you can get specific implementation back of an interface. &lt;br&gt;&lt;br&gt;interface IFoo { }&lt;br&gt;&lt;br&gt;public class Class1&lt;br&gt;{&lt;br&gt;    static void Main()&lt;br&gt;    {&lt;br&gt;        IFoo moreFoo = ReturnFoo(1);&lt;br&gt;    }&lt;br&gt;&lt;br&gt;    static internal IFoo ReturnFoo(int fooClassToReturn)&lt;br&gt;    {&lt;br&gt;        if(fooClassToReturn = 1)&lt;br&gt;        {&lt;br&gt;            FooClass1 foo = new FooClass1();&lt;br&gt;            return foo;&lt;br&gt;        }&lt;br&gt;        else&lt;br&gt;        {&lt;br&gt;            FooClass2 foo = new FooClass2();&lt;br&gt;            return foo;&lt;br&gt;        }&lt;br&gt;    }&lt;br&gt;}&lt;br&gt;&lt;br&gt;public class FooClass1: IFoo&lt;br&gt;{}&lt;br&gt;&lt;br&gt;public class FooClass2: IFoo&lt;br&gt;{}</description></item><item><title>re: Quiz: Instantiating an interface</title><link>http://blogs.msdn.com/brada/archive/2004/10/10/240523.aspx#240746</link><pubDate>Mon, 11 Oct 2004 14:10:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:240746</guid><dc:creator>Jeff Parker</dc:creator><description>Ooops small error with the if statement only one = sign, but this is more of an explanation, as you are gaurenteed to new up a class but the imlpementation is completely different.&lt;br&gt;&lt;br&gt;	interface IFoo&lt;br&gt;	{&lt;br&gt;		void WriteIt();&lt;br&gt;	}&lt;br&gt;&lt;br&gt;	public class Class1&lt;br&gt;	{&lt;br&gt;		static void Main()&lt;br&gt;		{&lt;br&gt;			IFoo moreFoo = ReturnFoo(1);&lt;br&gt;			IFoo moreFoo2 = ReturnFoo(2);&lt;br&gt;			moreFoo.WriteIt();&lt;br&gt;			moreFoo2.WriteIt();&lt;br&gt;		}&lt;br&gt;&lt;br&gt;		static internal IFoo ReturnFoo(int fooClassToReturn)&lt;br&gt;		{&lt;br&gt;			if(fooClassToReturn == 1)&lt;br&gt;			{&lt;br&gt;				FooClass1 foo = new FooClass1();&lt;br&gt;				return foo;&lt;br&gt;			}&lt;br&gt;			else&lt;br&gt;			{&lt;br&gt;				FooClass2 foo = new FooClass2();&lt;br&gt;				return foo;&lt;br&gt;			}&lt;br&gt;			&lt;br&gt;		}&lt;br&gt;	}&lt;br&gt;&lt;br&gt;	public class FooClass1: IFoo&lt;br&gt;	{&lt;br&gt;		public void WriteIt()&lt;br&gt;		{&lt;br&gt;			Console.WriteLine(&amp;quot;This is Foo 1&amp;quot;);&lt;br&gt;		}&lt;br&gt;	}&lt;br&gt;&lt;br&gt;	public class FooClass2: IFoo&lt;br&gt;	{&lt;br&gt;		public void WriteIt()&lt;br&gt;		{&lt;br&gt;			Console.WriteLine(&amp;quot;This is Foo 2&amp;quot;);&lt;br&gt;		}&lt;br&gt;	}</description></item><item><title>re: Quiz: Instantiating an interface</title><link>http://blogs.msdn.com/brada/archive/2004/10/10/240523.aspx#240826</link><pubDate>Mon, 11 Oct 2004 17:11:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:240826</guid><dc:creator>Kevin Westhead</dc:creator><description>I agree with Kevin Dente's comments. The use of the CoClass attribute allows you to write code that appears to instantiate an interface, although you are in fact instantiating an instance of the type identified in the CoClass attribute ctor.</description></item><item><title>re: Quiz: Instantiating an interface</title><link>http://blogs.msdn.com/brada/archive/2004/10/10/240523.aspx#240993</link><pubDate>Mon, 11 Oct 2004 22:46:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:240993</guid><dc:creator>Ilya Haykinson</dc:creator><description>A conjecture -- perhaps it's possible to set up a transparent proxy for the interface and mark the interface with a proxy attribute? I have tried this and failed, but I don't know everything there is to know about proxy creation.</description></item><item><title>re: Quiz: Instantiating an interface</title><link>http://blogs.msdn.com/brada/archive/2004/10/10/240523.aspx#241162</link><pubDate>Tue, 12 Oct 2004 09:14:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:241162</guid><dc:creator>Alex Campbell</dc:creator><description>&lt;br&gt;Was the interop answer the one you had in mind, Brad?</description></item><item><title>C#/CLR Quiz</title><link>http://blogs.msdn.com/brada/archive/2004/10/10/240523.aspx#245619</link><pubDate>Thu, 21 Oct 2004 15:07:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:245619</guid><dc:creator>Oleg Stepanov's Weblog</dc:creator><description>Recently I have been writing a managed interface to metadata and found several interesting things which I didn't know before. One of these things can be easily demonstrated with C# code, so I decided to make a quiz (just like...</description></item></channel></rss>