<?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>C# Quiz:  Will that compile?</title><link>http://blogs.msdn.com/brada/archive/2004/12/21/329270.aspx</link><description>A recent internal thread and a little nudge inspired me to offer this little quiz to keep the old grey matter working over the holiday break. In V2.0, does this code compile? If not why not and how would you fix it? Obviously the quiz is a little more</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: C# Quiz:  Will that compile?</title><link>http://blogs.msdn.com/brada/archive/2004/12/21/329270.aspx#329309</link><pubDate>Tue, 21 Dec 2004 23:44:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:329309</guid><dc:creator>Eric Maino</dc:creator><description>This should not compile becuase the compiler can't tell of which type the anonymous delegate is. &lt;br&gt;&lt;br&gt;If the function only took one type of delegate the code should compile beucase you wouldn't have any ambiguity.</description></item><item><title>re: C# Quiz:  Will that compile?</title><link>http://blogs.msdn.com/brada/archive/2004/12/21/329270.aspx#329312</link><pubDate>Tue, 21 Dec 2004 23:46:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:329312</guid><dc:creator>tum</dc:creator><description>I can't really see why it wouldn't unless the spec changed since I last looked.   You aren't required to provide anonymous method parameter lists anymore are you?&lt;br&gt;&lt;br&gt;I assume the line  wrapping within a string literal is an html thing  not your actual code :)</description></item><item><title>re: C# Quiz:  Will that compile?</title><link>http://blogs.msdn.com/brada/archive/2004/12/21/329270.aspx#329314</link><pubDate>Tue, 21 Dec 2004 23:49:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:329314</guid><dc:creator>tum</dc:creator><description>What are the prototypes of the other Thread  constructors? I only  have the 1.1 docs here and Thread only has one constructor.</description></item><item><title>re: C# Quiz:  Will that compile?</title><link>http://blogs.msdn.com/brada/archive/2004/12/21/329270.aspx#329328</link><pubDate>Wed, 22 Dec 2004 00:06:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:329328</guid><dc:creator>Matt Berther</dc:creator><description>Im guessing you need to do something like this:&lt;br&gt;&lt;br&gt;new Thread(new ThreadStart(delegate { Console.WriteLIne(&amp;quot;On another thread&amp;quot;); })).Start();&lt;br&gt;</description></item><item><title>re: C# Quiz:  Will that compile?</title><link>http://blogs.msdn.com/brada/archive/2004/12/21/329270.aspx#329346</link><pubDate>Wed, 22 Dec 2004 00:29:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:329346</guid><dc:creator>tum</dc:creator><description>new Thread(new ThreadStart(delegate { Console.WriteLIne(&amp;quot;On another thread&amp;quot;); })).Start(); &lt;br&gt;&lt;br&gt;I don't think that's it. threadstart *is* a delegate.&lt;br&gt;&lt;br&gt;Assuming Thread.ctor takes two different types of  delegates,  the solution would be to provide an explicit parameter list for the anonymous delegate&lt;br&gt;&lt;br&gt;i.e&lt;br&gt;&lt;br&gt;new Thread(delegate() { Console.WriteLine(&amp;quot;On another thread&amp;quot;); }).Start(); &lt;br&gt;&lt;br&gt;&lt;br&gt;Assuming Thread and ThreadStart look like they do in ver 1.1.&lt;br&gt;</description></item><item><title>Freudian slip</title><link>http://blogs.msdn.com/brada/archive/2004/12/21/329270.aspx#329363</link><pubDate>Wed, 22 Dec 2004 00:52:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:329363</guid><dc:creator>some guy</dc:creator><description>they say a freudian slip is when you say one thing but mean your mother.  or in this case, &amp;quot;the old grey mater&amp;quot; which is not a very kind way of referring to her. :-)</description></item><item><title>re: C# Quiz:  Will that compile?</title><link>http://blogs.msdn.com/brada/archive/2004/12/21/329270.aspx#329526</link><pubDate>Wed, 22 Dec 2004 03:35:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:329526</guid><dc:creator>James Manning</dc:creator><description>First Close/Dispose and now this! :)</description></item><item><title>re: C# Quiz:  Will that compile?</title><link>http://blogs.msdn.com/brada/archive/2004/12/21/329270.aspx#329538</link><pubDate>Wed, 22 Dec 2004 04:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:329538</guid><dc:creator>Brad Abrams[MSFT]</dc:creator><description>Some guy -- thanks, fixed ;-)  I hope my mother doesn't see this ;-)</description></item><item><title>re: C# Quiz:  Will that compile?</title><link>http://blogs.msdn.com/brada/archive/2004/12/21/329270.aspx#329559</link><pubDate>Wed, 22 Dec 2004 04:54:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:329559</guid><dc:creator>Judah</dc:creator><description>&lt;br&gt;new Thread(delegate &lt;br&gt;{ &lt;br&gt;    Console.WriteLine(&amp;quot;On another thread&amp;quot;); &lt;br&gt;}).Start();&lt;br&gt;&lt;br&gt;Would work if 1.1 supported anonymous methods. :-) But in 2.0, Thread.Start has overloads allowing a parameterized thread start, which means the compiler can't figure out which one to use, ThreadStart or ParameterizedThreadStart. So no, it won't compile.&lt;br&gt;&lt;br&gt;This should compile:&lt;br&gt;&lt;br&gt;// tell the compiler it should be a ThreadStart&lt;br&gt;new Thread((ThreadStart)delegate&lt;br&gt;{&lt;br&gt;     Console.WriteLine(&amp;quot;On another thread&amp;quot;);&lt;br&gt;});</description></item><item><title>re: C# Quiz:  Will that compile?</title><link>http://blogs.msdn.com/brada/archive/2004/12/21/329270.aspx#329573</link><pubDate>Wed, 22 Dec 2004 05:31:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:329573</guid><dc:creator>Joe Duffy</dc:creator><description>Judah brings up an interesting point...&lt;br&gt;&lt;br&gt;Who would've thunk that introducing a new ctor overload would end up breaking people? Interestingly, though, if we had anonymous delegate support in v1.1 and folks coded up something like what you've shown, introducing the new Thread.ctor(ParameterizedThreadStart) overload would prevent that same source from compiling without modification on v2.0.&lt;br&gt;&lt;br&gt;Luckily this isn't the case. :)&lt;br&gt;&lt;br&gt;Hmm!</description></item><item><title>re: C# Quiz:  Will that compile?</title><link>http://blogs.msdn.com/brada/archive/2004/12/21/329270.aspx#329601</link><pubDate>Wed, 22 Dec 2004 06:17:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:329601</guid><dc:creator>tum</dc:creator><description>Judah,&lt;br&gt;&lt;br&gt;I suspected they may have added a thread start  with state attached  (tho that wouldn't be needed if you used an  anonymous method worth closures ;)). &lt;br&gt;&lt;br&gt;Does this compile?&lt;br&gt;&lt;br&gt;new Thread(delegate() { Console.WriteLine(&amp;quot;On another thread&amp;quot;); }).Start(); &lt;br&gt;&lt;br&gt;&lt;br&gt;The empty parameter list  should be enough for the compiler to work out which delegate type you want constructed. ...</description></item><item><title>re: C# Quiz:  Will that compile?</title><link>http://blogs.msdn.com/brada/archive/2004/12/21/329270.aspx#330300</link><pubDate>Thu, 23 Dec 2004 00:12:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:330300</guid><dc:creator>Judah</dc:creator><description>Yes, with the parameterless delegate, the compiler can figure out that you're using the parameterless ThreadStart delegate.</description></item><item><title>C# Quiz: Will that compile? [Answer]</title><link>http://blogs.msdn.com/brada/archive/2004/12/21/329270.aspx#332864</link><pubDate>Mon, 27 Dec 2004 22:55:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:332864</guid><dc:creator>Brad Abrams </dc:creator><description /></item><item><title>C# Quiz: Will that compile?</title><link>http://blogs.msdn.com/brada/archive/2004/12/21/329270.aspx#333192</link><pubDate>Tue, 28 Dec 2004 14:31:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:333192</guid><dc:creator>Managed from down under</dc:creator><description /></item><item><title>re: C# Quiz:  Will that compile?</title><link>http://blogs.msdn.com/brada/archive/2004/12/21/329270.aspx#346105</link><pubDate>Tue, 04 Jan 2005 07:21:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:346105</guid><dc:creator>Shon Dot Net Dude</dc:creator><description>It will not compile &amp;lt;Span&amp;gt;</description></item><item><title>ParameterisedThreadStart</title><link>http://blogs.msdn.com/brada/archive/2004/12/21/329270.aspx#667447</link><pubDate>Sun, 16 Jul 2006 18:14:38 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:667447</guid><dc:creator>Community Blogs</dc:creator><description>Just to prove that I am a true geek I thought I would tackle Brad Abrams latest C# quiz. The simple answer</description></item></channel></rss>