<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: C# 4.0 Optional Parameters &#8211; Exploration.</title>
	<atom:link href="http://elegantcode.com/2010/01/28/c-4-0-optional-parameters-exploration/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com/2010/01/28/c-4-0-optional-parameters-exploration/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=c-4-0-optional-parameters-exploration</link>
	<description></description>
	<lastBuildDate>Sun, 12 Feb 2012 18:54:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
	<item>
		<title>By: Michael Mcdaniel</title>
		<link>http://elegantcode.com/2010/01/28/c-4-0-optional-parameters-exploration/comment-page-1/#comment-54689</link>
		<dc:creator>Michael Mcdaniel</dc:creator>
		<pubDate>Wed, 24 Mar 2010 17:17:01 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/01/28/c-4-0-optional-parameters-exploration/#comment-54689</guid>
		<description>&lt;a href=&quot;#comment-54688&quot; rel=&quot;nofollow&quot;&gt;@Michael McDaniel &lt;/a&gt; 
&quot;c-plus-plus&quot; not c</description>
		<content:encoded><![CDATA[<p><a href="#comment-54688" rel="nofollow">@Michael McDaniel </a><br />
&#8220;c-plus-plus&#8221; not c</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael McDaniel</title>
		<link>http://elegantcode.com/2010/01/28/c-4-0-optional-parameters-exploration/comment-page-1/#comment-54688</link>
		<dc:creator>Michael McDaniel</dc:creator>
		<pubDate>Wed, 24 Mar 2010 17:15:39 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/01/28/c-4-0-optional-parameters-exploration/#comment-54688</guid>
		<description>&lt;a href=&quot;#comment-53217&quot; rel=&quot;nofollow&quot;&gt;@Steve Py &lt;/a&gt; 
Actually, this feature brings it more inline with c  .  It&#039;s one of the few things I&#039;ve missed when I switched to C#.</description>
		<content:encoded><![CDATA[<p><a href="#comment-53217" rel="nofollow">@Steve Py </a><br />
Actually, this feature brings it more inline with c  .  It&#8217;s one of the few things I&#8217;ve missed when I switched to C#.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: C# 4.0: ???????, ??????, ?????, ????? - ???? ???????????? ?????????? - Microsoft User Group ???????</title>
		<link>http://elegantcode.com/2010/01/28/c-4-0-optional-parameters-exploration/comment-page-1/#comment-54120</link>
		<dc:creator>C# 4.0: ???????, ??????, ?????, ????? - ???? ???????????? ?????????? - Microsoft User Group ???????</dc:creator>
		<pubDate>Sun, 28 Feb 2010 16:10:46 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/01/28/c-4-0-optional-parameters-exploration/#comment-54120</guid>
		<description>[...] C# 4.0 Optional Parameters &#8211; Exploration [...]</description>
		<content:encoded><![CDATA[<p>[...] C# 4.0 Optional Parameters &ndash; Exploration [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jason Jarrett</title>
		<link>http://elegantcode.com/2010/01/28/c-4-0-optional-parameters-exploration/comment-page-1/#comment-53995</link>
		<dc:creator>Jason Jarrett</dc:creator>
		<pubDate>Wed, 24 Feb 2010 15:45:27 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/01/28/c-4-0-optional-parameters-exploration/#comment-53995</guid>
		<description>&lt;a href=&quot;#comment-53987&quot; rel=&quot;nofollow&quot;&gt;@Joey&lt;/a&gt; 
First question - Yes - take a look at the first two unit tests in this post...
- Should_get_the_concrete_class_default_value
- Should_get_the_interface_default_value

Second Question - What would you expect this to do?

I expected the call to Bar() to call the correct bar (not the one with a default parameter) Not sure why you would want to provide two methods of the same name where one has a default. I think the idea of the parameter defaults is so you don&#039;t have to provide extra overloads.

I tested it and the two following tests both threw NotImplementedExceptions.

    public interface IFooJoey
    {
        int ParamValue { get; }
        void Bar();
        void Bar(int paramValue = 1);
    }

    public class FooJoey : IFooJoey
    {
        public int ParamValue { get; private set; }

        public void Bar()
        {
            throw new NotImplementedException();
        }

        public void Bar(int paramValue)
        {
            ParamValue = paramValue;
        }
    }


    [TestClass]
    public class UnitTest1Joey
    {
        [TestMethod]
        public void Should_get_the_concrete_class_default_value()
        {
            FooJoey f1 = new FooJoey();
            f1.Bar();
            f1.ParamValue.ShouldBeEqualTo(1);
        }

        [TestMethod]
        public void Should_get_the_interface_default_value()
        {
            IFooJoey f = new FooJoey();
            f.Bar();
            f.ParamValue.ShouldBeEqualTo(1);
        }
    }</description>
		<content:encoded><![CDATA[<p><a href="#comment-53987" rel="nofollow">@Joey</a><br />
First question &#8211; Yes &#8211; take a look at the first two unit tests in this post&#8230;<br />
- Should_get_the_concrete_class_default_value<br />
- Should_get_the_interface_default_value</p>
<p>Second Question &#8211; What would you expect this to do?</p>
<p>I expected the call to Bar() to call the correct bar (not the one with a default parameter) Not sure why you would want to provide two methods of the same name where one has a default. I think the idea of the parameter defaults is so you don&#8217;t have to provide extra overloads.</p>
<p>I tested it and the two following tests both threw NotImplementedExceptions.</p>
<p>    public interface IFooJoey<br />
    {<br />
        int ParamValue { get; }<br />
        void Bar();<br />
        void Bar(int paramValue = 1);<br />
    }</p>
<p>    public class FooJoey : IFooJoey<br />
    {<br />
        public int ParamValue { get; private set; }</p>
<p>        public void Bar()<br />
        {<br />
            throw new NotImplementedException();<br />
        }</p>
<p>        public void Bar(int paramValue)<br />
        {<br />
            ParamValue = paramValue;<br />
        }<br />
    }</p>
<p>    [TestClass]<br />
    public class UnitTest1Joey<br />
    {<br />
        [TestMethod]<br />
        public void Should_get_the_concrete_class_default_value()<br />
        {<br />
            FooJoey f1 = new FooJoey();<br />
            f1.Bar();<br />
            f1.ParamValue.ShouldBeEqualTo(1);<br />
        }</p>
<p>        [TestMethod]<br />
        public void Should_get_the_interface_default_value()<br />
        {<br />
            IFooJoey f = new FooJoey();<br />
            f.Bar();<br />
            f.ParamValue.ShouldBeEqualTo(1);<br />
        }<br />
    }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joey</title>
		<link>http://elegantcode.com/2010/01/28/c-4-0-optional-parameters-exploration/comment-page-1/#comment-53987</link>
		<dc:creator>Joey</dc:creator>
		<pubDate>Wed, 24 Feb 2010 13:14:49 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/01/28/c-4-0-optional-parameters-exploration/#comment-53987</guid>
		<description>First question:
in your example above, you were able to get different default values, depending on what you casted Foo to.  Would this work the same way the following situation?

IFoo firstFoo = new Foo(); firstFoo.Bar() // 1
Foo secondFoo = new Foo(); secondFoo.Bar() // 1000

Second question:
How would method Overloading work in this situation?

public interface IFoo
{
    int ParamValue { get; }
    void Bar();
    void Bar(int paramValue = 1);
}</description>
		<content:encoded><![CDATA[<p>First question:<br />
in your example above, you were able to get different default values, depending on what you casted Foo to.  Would this work the same way the following situation?</p>
<p>IFoo firstFoo = new Foo(); firstFoo.Bar() // 1<br />
Foo secondFoo = new Foo(); secondFoo.Bar() // 1000</p>
<p>Second question:<br />
How would method Overloading work in this situation?</p>
<p>public interface IFoo<br />
{<br />
    int ParamValue { get; }<br />
    void Bar();<br />
    void Bar(int paramValue = 1);<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: C# 4.0 New Features, Videos, Articles and Books - IT Shala</title>
		<link>http://elegantcode.com/2010/01/28/c-4-0-optional-parameters-exploration/comment-page-1/#comment-53510</link>
		<dc:creator>C# 4.0 New Features, Videos, Articles and Books - IT Shala</dc:creator>
		<pubDate>Wed, 10 Feb 2010 15:11:37 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/01/28/c-4-0-optional-parameters-exploration/#comment-53510</guid>
		<description>[...] C# 4.0 Optional Parameters – Exploration [...]</description>
		<content:encoded><![CDATA[<p>[...] C# 4.0 Optional Parameters – Exploration [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Yann Trevin</title>
		<link>http://elegantcode.com/2010/01/28/c-4-0-optional-parameters-exploration/comment-page-1/#comment-53252</link>
		<dc:creator>Yann Trevin</dc:creator>
		<pubDate>Sat, 30 Jan 2010 16:53:17 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/01/28/c-4-0-optional-parameters-exploration/#comment-53252</guid>
		<description>Agree with John. This behavior is really annoying. It may introduce very subtle bugs. I wonder if this feature actually brings more good or more evil.</description>
		<content:encoded><![CDATA[<p>Agree with John. This behavior is really annoying. It may introduce very subtle bugs. I wonder if this feature actually brings more good or more evil.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/01/28/c-4-0-optional-parameters-exploration/comment-page-1/#comment-53237</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Fri, 29 Jan 2010 15:11:38 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/01/28/c-4-0-optional-parameters-exploration/#comment-53237</guid>
		<description>Not so sure I like that the default value uses the interface one when when you do this:

((IFoo) new Foo()).Bar() – would use the value of ‘1’.

Seems like it violated the principle of least surprise.  Maybe it is just me though.</description>
		<content:encoded><![CDATA[<p>Not so sure I like that the default value uses the interface one when when you do this:</p>
<p>((IFoo) new Foo()).Bar() – would use the value of ‘1’.</p>
<p>Seems like it violated the principle of least surprise.  Maybe it is just me though.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: The Morning Brew - Chris Alcock &#187; The Morning Brew #528</title>
		<link>http://elegantcode.com/2010/01/28/c-4-0-optional-parameters-exploration/comment-page-1/#comment-53223</link>
		<dc:creator>The Morning Brew - Chris Alcock &#187; The Morning Brew #528</dc:creator>
		<pubDate>Fri, 29 Jan 2010 09:42:12 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/01/28/c-4-0-optional-parameters-exploration/#comment-53223</guid>
		<description>[...] C# 4.0 Optional Parameters - Exploration. - Jason Jarrett explores the use of optional parameters in interfaces, looking at some of the more complex scenarios which the use of optional parameters can cause. [...]</description>
		<content:encoded><![CDATA[<p>[...] C# 4.0 Optional Parameters &#8211; Exploration. &#8211; Jason Jarrett explores the use of optional parameters in interfaces, looking at some of the more complex scenarios which the use of optional parameters can cause. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve Py</title>
		<link>http://elegantcode.com/2010/01/28/c-4-0-optional-parameters-exploration/comment-page-1/#comment-53217</link>
		<dc:creator>Steve Py</dc:creator>
		<pubDate>Fri, 29 Jan 2010 06:21:09 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/01/28/c-4-0-optional-parameters-exploration/#comment-53217</guid>
		<description>One step closer to VB...</description>
		<content:encoded><![CDATA[<p>One step closer to VB&#8230;</p>
]]></content:encoded>
	</item>
</channel>
</rss>

