<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>2,000 Things You Should Know About C#</title>
	<atom:link href="http://csharp.2000things.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://csharp.2000things.com</link>
	<description>Everything a C# Developer Needs to Know, in Bite-Sized Chunks</description>
	<lastBuildDate>Fri, 25 May 2012 11:05:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='csharp.2000things.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/5021f502b3504edbf7e6bf53c55000e0?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>2,000 Things You Should Know About C#</title>
		<link>http://csharp.2000things.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://csharp.2000things.com/osd.xml" title="2,000 Things You Should Know About C#" />
	<atom:link rel='hub' href='http://csharp.2000things.com/?pushpress=hub'/>
		<item>
		<title>#591 &#8211; How Optional Parameters Look with Intellisense</title>
		<link>http://csharp.2000things.com/2012/05/25/591-how-optional-parameters-look-with-intellisense/</link>
		<comments>http://csharp.2000things.com/2012/05/25/591-how-optional-parameters-look-with-intellisense/#comments</comments>
		<pubDate>Fri, 25 May 2012 11:00:41 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Intellisense]]></category>
		<category><![CDATA[Optional Parameters]]></category>

		<guid isPermaLink="false">http://csharp.2000things.com/?p=4992</guid>
		<description><![CDATA[When you&#8217;re working in Visual Studio and you start typing in the name of a method, Intellisense will show you any optional parameters that the method has. In the example below, we&#8217;ve started entering code to create a new instance of a Dog object.  Intellisense shows us a list of the optional parameters that are defined [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=csharp.2000things.com&#038;blog=14273916&#038;post=4992&#038;subd=2000thingscsharp&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When you&#8217;re working in Visual Studio and you start typing in the name of a method, Intellisense will show you any optional parameters that the method has.</p>
<p>In the example below, we&#8217;ve started entering code to create a new instance of a <strong>Dog</strong> object.  Intellisense shows us a list of the optional parameters that are defined for the constructor.</p>
<p><a href="http://2000thingscsharp.files.wordpress.com/2012/05/591-001.png"><img class="alignnone size-full wp-image-4993" title="591-001" src="http://2000thingscsharp.files.wordpress.com/2012/05/591-001.png?w=630&h=71" alt="" width="630" height="71" /></a></p>
<br />Filed under: <a href='http://csharp.2000things.com/category/visual-studio/'>Visual Studio</a> Tagged: <a href='http://csharp.2000things.com/tag/c/'>C#</a>, <a href='http://csharp.2000things.com/tag/intellisense/'>Intellisense</a>, <a href='http://csharp.2000things.com/tag/optional-parameters/'>Optional Parameters</a>, <a href='http://csharp.2000things.com/tag/visual-studio/'>Visual Studio</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/2000thingscsharp.wordpress.com/4992/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/2000thingscsharp.wordpress.com/4992/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/2000thingscsharp.wordpress.com/4992/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/2000thingscsharp.wordpress.com/4992/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/2000thingscsharp.wordpress.com/4992/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/2000thingscsharp.wordpress.com/4992/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/2000thingscsharp.wordpress.com/4992/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/2000thingscsharp.wordpress.com/4992/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/2000thingscsharp.wordpress.com/4992/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/2000thingscsharp.wordpress.com/4992/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/2000thingscsharp.wordpress.com/4992/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/2000thingscsharp.wordpress.com/4992/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/2000thingscsharp.wordpress.com/4992/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/2000thingscsharp.wordpress.com/4992/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=csharp.2000things.com&#038;blog=14273916&#038;post=4992&#038;subd=2000thingscsharp&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://csharp.2000things.com/2012/05/25/591-how-optional-parameters-look-with-intellisense/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8922e4d5254d602ba3ed32dd073b5a4e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">spsexton</media:title>
		</media:content>

		<media:content url="http://2000thingscsharp.files.wordpress.com/2012/05/591-001.png" medium="image">
			<media:title type="html">591-001</media:title>
		</media:content>
	</item>
		<item>
		<title>#590 &#8211; Optional Parameters in Constructors</title>
		<link>http://csharp.2000things.com/2012/05/24/590-optional-parameters-in-constructors/</link>
		<comments>http://csharp.2000things.com/2012/05/24/590-optional-parameters-in-constructors/#comments</comments>
		<pubDate>Thu, 24 May 2012 11:00:24 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Classes]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Constructor]]></category>
		<category><![CDATA[Optional Parameter]]></category>

		<guid isPermaLink="false">http://csharp.2000things.com/?p=4983</guid>
		<description><![CDATA[You&#8217;ll typically see optional parameters in methods.  But you can also define an optional parameter in a constructor: &#160; Optional parameters in constructors avoid the need to chain constructors. &#160; Filed under: Classes Tagged: C#, Classes, Constructor, Optional Parameter<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=csharp.2000things.com&#038;blog=14273916&#038;post=4983&#038;subd=2000thingscsharp&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>You&#8217;ll typically see <a href="http://csharp.2000things.com/2012/05/16/584-defining-an-optional-parameter/">optional parameters</a> in methods.  But you can also define an optional parameter in a constructor:</p>
<p><pre class="brush: csharp;">
        public string Name { get; set; }
        public int Age { get; set; }
        public string FavoriteToy { get; set; }
        public Dog Father { get; set; }
        public Dog Mother { get; set; }

        public Dog(string name, int age = 1, string favToy = &quot;Bone&quot;,
            Dog father = null, Dog mother = null)
        {
            Name = name;
            Age = age;
            FavoriteToy = favToy;
            Father = father;
            Mother = mother;
        }
</pre></p>
<p>&nbsp;</p>
<p><pre class="brush: csharp;">
            Dog kirby = new Dog(&quot;Kirby&quot;, 15, &quot;Ball&quot;);
            Dog sonOfKirby = new Dog(&quot;Ferbie&quot;, 2, &quot;Frisbee&quot;, kirby);
</pre></p>
<p><a href="http://2000thingscsharp.files.wordpress.com/2012/05/590-001.png"><img class="alignnone size-full wp-image-4987" title="590-001" src="http://2000thingscsharp.files.wordpress.com/2012/05/590-001.png?w=630" alt=""   /></a><br />
Optional parameters in constructors avoid the need to chain constructors.</p>
<p>&nbsp;</p>
<br />Filed under: <a href='http://csharp.2000things.com/category/classes/'>Classes</a> Tagged: <a href='http://csharp.2000things.com/tag/c/'>C#</a>, <a href='http://csharp.2000things.com/tag/classes/'>Classes</a>, <a href='http://csharp.2000things.com/tag/constructor/'>Constructor</a>, <a href='http://csharp.2000things.com/tag/optional-parameter/'>Optional Parameter</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/2000thingscsharp.wordpress.com/4983/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/2000thingscsharp.wordpress.com/4983/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/2000thingscsharp.wordpress.com/4983/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/2000thingscsharp.wordpress.com/4983/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/2000thingscsharp.wordpress.com/4983/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/2000thingscsharp.wordpress.com/4983/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/2000thingscsharp.wordpress.com/4983/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/2000thingscsharp.wordpress.com/4983/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/2000thingscsharp.wordpress.com/4983/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/2000thingscsharp.wordpress.com/4983/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/2000thingscsharp.wordpress.com/4983/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/2000thingscsharp.wordpress.com/4983/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/2000thingscsharp.wordpress.com/4983/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/2000thingscsharp.wordpress.com/4983/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=csharp.2000things.com&#038;blog=14273916&#038;post=4983&#038;subd=2000thingscsharp&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://csharp.2000things.com/2012/05/24/590-optional-parameters-in-constructors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8922e4d5254d602ba3ed32dd073b5a4e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">spsexton</media:title>
		</media:content>

		<media:content url="http://2000thingscsharp.files.wordpress.com/2012/05/590-001.png" medium="image">
			<media:title type="html">590-001</media:title>
		</media:content>
	</item>
		<item>
		<title>#589 &#8211; Optional Parameters Must Be Input Parameters</title>
		<link>http://csharp.2000things.com/2012/05/23/589-optional-parameters-must-be-input-parameters/</link>
		<comments>http://csharp.2000things.com/2012/05/23/589-optional-parameters-must-be-input-parameters/#comments</comments>
		<pubDate>Wed, 23 May 2012 11:00:36 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Methods]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Optional Parameters]]></category>

		<guid isPermaLink="false">http://csharp.2000things.com/?p=4976</guid>
		<description><![CDATA[An optional parameter must be an input parameter.  It can&#8217;t therefore be modified by the out or ref keywords.  An optional parameter also cannot be modified by the params keyword. Filed under: Methods Tagged: C#, Methods, Optional Parameters<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=csharp.2000things.com&#038;blog=14273916&#038;post=4976&#038;subd=2000thingscsharp&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>An <a href="http://csharp.2000things.com/2012/05/16/584-defining-an-optional-parameter/">optional parameter</a> must be an input parameter.  It can&#8217;t therefore be modified by the <strong>out</strong> or <strong>ref</strong> keywords.  An optional parameter also cannot be modified by the <strong>params </strong>keyword.</p>
<p><pre class="brush: csharp;">
        // OK: numTimesToRead is an input parameter (passed by value)
        static void ReadBook(string title, int numTimesToRead = 1)
        {
        }

        // NO: out parameter can't have default value
        static void ReadBook2(string title, out int yourRating = 3)
        {
            yourRating = 4;
        }

        // NO: ref parameter can't have default value
        static void ReadBook3(string title, ref string yourOpinion = &quot;Unknown&quot;)
        {
        }

        // NO: Parameter array can't have default value
        static void ReadBook4(string title, params string[] characters = null)
        {
        }

</pre><br />
<a href="http://2000thingscsharp.files.wordpress.com/2012/05/589-001.png"><img class="alignnone size-full wp-image-4979" title="589-001" src="http://2000thingscsharp.files.wordpress.com/2012/05/589-001.png?w=630" alt=""   /></a></pre>
<br />Filed under: <a href='http://csharp.2000things.com/category/methods/'>Methods</a> Tagged: <a href='http://csharp.2000things.com/tag/c/'>C#</a>, <a href='http://csharp.2000things.com/tag/methods/'>Methods</a>, <a href='http://csharp.2000things.com/tag/optional-parameters/'>Optional Parameters</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/2000thingscsharp.wordpress.com/4976/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/2000thingscsharp.wordpress.com/4976/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/2000thingscsharp.wordpress.com/4976/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/2000thingscsharp.wordpress.com/4976/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/2000thingscsharp.wordpress.com/4976/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/2000thingscsharp.wordpress.com/4976/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/2000thingscsharp.wordpress.com/4976/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/2000thingscsharp.wordpress.com/4976/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/2000thingscsharp.wordpress.com/4976/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/2000thingscsharp.wordpress.com/4976/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/2000thingscsharp.wordpress.com/4976/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/2000thingscsharp.wordpress.com/4976/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/2000thingscsharp.wordpress.com/4976/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/2000thingscsharp.wordpress.com/4976/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=csharp.2000things.com&#038;blog=14273916&#038;post=4976&#038;subd=2000thingscsharp&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://csharp.2000things.com/2012/05/23/589-optional-parameters-must-be-input-parameters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8922e4d5254d602ba3ed32dd073b5a4e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">spsexton</media:title>
		</media:content>

		<media:content url="http://2000thingscsharp.files.wordpress.com/2012/05/589-001.png" medium="image">
			<media:title type="html">589-001</media:title>
		</media:content>
	</item>
		<item>
		<title>#588 &#8211; A Default Parameter Value Can Be Null</title>
		<link>http://csharp.2000things.com/2012/05/22/588-a-default-parameter-value-can-be-null/</link>
		<comments>http://csharp.2000things.com/2012/05/22/588-a-default-parameter-value-can-be-null/#comments</comments>
		<pubDate>Tue, 22 May 2012 11:00:52 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Methods]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[null]]></category>
		<category><![CDATA[Optional Parameters]]></category>

		<guid isPermaLink="false">http://csharp.2000things.com/?p=4969</guid>
		<description><![CDATA[When defining optional parameters and providing a default value for the parameter, you can use a value of null for a reference-typed parameter.  null is actually the only valid default value that you can use for a reference-typed parameter. Filed under: Methods Tagged: C#, Methods, null, Optional Parameters<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=csharp.2000things.com&#038;blog=14273916&#038;post=4969&#038;subd=2000thingscsharp&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When defining optional parameters and providing a default value for the parameter, you can use a value of <strong>null</strong> for a reference-typed parameter.  <strong>null</strong> is actually the only valid default value that you can use for a reference-typed parameter.</p>
<p><pre class="brush: csharp;">
        static void LogDogInfo(Dog myDog, Dog anotherDog = null)
        {
            Console.WriteLine(&quot;My dog is {0}&quot;, myDog.Name);
            if (anotherDog != null)
                Console.WriteLine(&quot;  And there is also {0}&quot;, anotherDog.Name);
        }

        static void Main()
        {
            Dog dog1 = new Dog(&quot;Kirby&quot;, 15);
            Dog dog2 = new Dog(&quot;Jack&quot;, 17);

            LogDogInfo(dog1);
            LogDogInfo(dog2, dog1);
        }
</pre><br />
<a href="http://2000thingscsharp.files.wordpress.com/2012/05/588-001.png"><img class="alignnone size-full wp-image-4972" title="588-001" src="http://2000thingscsharp.files.wordpress.com/2012/05/588-001.png?w=630" alt=""   /></a></pre>
<br />Filed under: <a href='http://csharp.2000things.com/category/methods/'>Methods</a> Tagged: <a href='http://csharp.2000things.com/tag/c/'>C#</a>, <a href='http://csharp.2000things.com/tag/methods/'>Methods</a>, <a href='http://csharp.2000things.com/tag/null/'>null</a>, <a href='http://csharp.2000things.com/tag/optional-parameters/'>Optional Parameters</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/2000thingscsharp.wordpress.com/4969/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/2000thingscsharp.wordpress.com/4969/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/2000thingscsharp.wordpress.com/4969/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/2000thingscsharp.wordpress.com/4969/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/2000thingscsharp.wordpress.com/4969/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/2000thingscsharp.wordpress.com/4969/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/2000thingscsharp.wordpress.com/4969/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/2000thingscsharp.wordpress.com/4969/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/2000thingscsharp.wordpress.com/4969/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/2000thingscsharp.wordpress.com/4969/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/2000thingscsharp.wordpress.com/4969/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/2000thingscsharp.wordpress.com/4969/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/2000thingscsharp.wordpress.com/4969/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/2000thingscsharp.wordpress.com/4969/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=csharp.2000things.com&#038;blog=14273916&#038;post=4969&#038;subd=2000thingscsharp&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://csharp.2000things.com/2012/05/22/588-a-default-parameter-value-can-be-null/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8922e4d5254d602ba3ed32dd073b5a4e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">spsexton</media:title>
		</media:content>

		<media:content url="http://2000thingscsharp.files.wordpress.com/2012/05/588-001.png" medium="image">
			<media:title type="html">588-001</media:title>
		</media:content>
	</item>
		<item>
		<title>#587 &#8211; If Provided, Optional Arguments Must Be in Correct Order</title>
		<link>http://csharp.2000things.com/2012/05/21/587-if-provided-optional-arguments-must-be-in-correct-order/</link>
		<comments>http://csharp.2000things.com/2012/05/21/587-if-provided-optional-arguments-must-be-in-correct-order/#comments</comments>
		<pubDate>Mon, 21 May 2012 11:00:10 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Methods]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Optional Parameters]]></category>
		<category><![CDATA[Parameters]]></category>

		<guid isPermaLink="false">http://csharp.2000things.com/?p=4963</guid>
		<description><![CDATA[When you choose to include arguments for optional parameters on a method, you must specify the arguments in the proper order (just like required parameters). In the example below, we define a method with one required parameter and three optional parameters.  When we call it, we must provide a value for the yourName parameter.  Then we [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=csharp.2000things.com&#038;blog=14273916&#038;post=4963&#038;subd=2000thingscsharp&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When you choose to include arguments for optional parameters on a method, you must specify the arguments in the proper order (just like required parameters).</p>
<p>In the example below, we define a method with one required parameter and three optional parameters.  When we call it, we must provide a value for the <strong>yourName</strong> parameter.  Then we can provide values for one, two or all three of the optional parameters, in the following combinations:</p>
<ul>
<li>book</li>
<li>book, play</li>
<li>book, play, poem</li>
</ul>
<p><pre class="brush: csharp;">
        static void Favorites(
            string yourName,
            string book = &quot;Moby Dick&quot;,
            string play = &quot;Henry V&quot;,
            string poem = &quot;The Road Not Taken&quot;)
        {
            Console.WriteLine(&quot;{0}'s favorites:&quot;, yourName);
            Console.WriteLine(&quot;  Book: {0}&quot;, book);
            Console.WriteLine(&quot;  Play: {0}&quot;, play);
            Console.WriteLine(&quot;  Poem: {0}&quot;, poem);
        }

        static void Main()
        {
            Favorites(&quot;Sean&quot;);
            Favorites(&quot;Sergei&quot;, &quot;Anna Karenina&quot;);
            Favorites(&quot;Pablo&quot;, &quot;Don Quixote&quot;, &quot;Canción de cuna&quot;);
            Favorites(&quot;Nigel&quot;, &quot;David Copperfield&quot;, &quot;Hamlet&quot;, &quot;Ode to Duty&quot;);
        }
</pre><br />
<a href="http://2000thingscsharp.files.wordpress.com/2012/05/587-001.png"><img class="alignnone size-full wp-image-4966" title="587-001" src="http://2000thingscsharp.files.wordpress.com/2012/05/587-001.png?w=630" alt=""   /></a></pre>
<br />Filed under: <a href='http://csharp.2000things.com/category/methods/'>Methods</a> Tagged: <a href='http://csharp.2000things.com/tag/c/'>C#</a>, <a href='http://csharp.2000things.com/tag/methods/'>Methods</a>, <a href='http://csharp.2000things.com/tag/optional-parameters/'>Optional Parameters</a>, <a href='http://csharp.2000things.com/tag/parameters/'>Parameters</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/2000thingscsharp.wordpress.com/4963/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/2000thingscsharp.wordpress.com/4963/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/2000thingscsharp.wordpress.com/4963/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/2000thingscsharp.wordpress.com/4963/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/2000thingscsharp.wordpress.com/4963/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/2000thingscsharp.wordpress.com/4963/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/2000thingscsharp.wordpress.com/4963/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/2000thingscsharp.wordpress.com/4963/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/2000thingscsharp.wordpress.com/4963/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/2000thingscsharp.wordpress.com/4963/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/2000thingscsharp.wordpress.com/4963/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/2000thingscsharp.wordpress.com/4963/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/2000thingscsharp.wordpress.com/4963/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/2000thingscsharp.wordpress.com/4963/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=csharp.2000things.com&#038;blog=14273916&#038;post=4963&#038;subd=2000thingscsharp&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://csharp.2000things.com/2012/05/21/587-if-provided-optional-arguments-must-be-in-correct-order/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8922e4d5254d602ba3ed32dd073b5a4e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">spsexton</media:title>
		</media:content>

		<media:content url="http://2000thingscsharp.files.wordpress.com/2012/05/587-001.png" medium="image">
			<media:title type="html">587-001</media:title>
		</media:content>
	</item>
		<item>
		<title>#586 &#8211; Default Values for Optional Parameters Must Be Constants</title>
		<link>http://csharp.2000things.com/2012/05/18/586-default-values-for-optional-parameters-must-be-constants/</link>
		<comments>http://csharp.2000things.com/2012/05/18/586-default-values-for-optional-parameters-must-be-constants/#comments</comments>
		<pubDate>Fri, 18 May 2012 11:00:59 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Methods]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Constants]]></category>
		<category><![CDATA[Optional Parameters]]></category>

		<guid isPermaLink="false">http://csharp.2000things.com/?p=4956</guid>
		<description><![CDATA[When you specify a default value for an optional parameter, that value must be a constant, of the same type as the parameter.  The expression must be able to be evaluted at compile-time.  The parameter&#8217;s default value can be one of the following: A constant expression (see below) new S(),  where S is a value-type (parameters [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=csharp.2000things.com&#038;blog=14273916&#038;post=4956&#038;subd=2000thingscsharp&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When you specify a default value for an <a href="http://csharp.2000things.com/2012/05/16/584-defining-an-optional-parameter/">optional parameter</a>, that value must be a constant, of the same type as the parameter.  The expression must be able to be evaluted at compile-time.  The parameter&#8217;s default value can be one of the following:</p>
<ul>
<li>A constant expression (see below)</li>
<li><strong>new S()</strong>,  where <strong>S</strong> is a value-type (parameters not allowed on constructor)</li>
</ul>
<p>A constant expression is one that can be fully determined at compile-time.  In other words, you can use any expression that you&#8217;d use in the initialization of a <a href="http://csharp.2000things.com/2011/05/06/319-you-initialize-a-constant-using-an-expression/">constant</a>.</p>
<p>For reference types, the expression must be <strong>null</strong>, with the exception of the <strong>string</strong> type.</p>
<p><pre class="brush: csharp;">
        private const int OFFSET = 1;

        static void Optional1(int x = 5 + OFFSET, double y = 1.0/3.0) { }
        static void Optional2(Point3D fln = new Point3D()) { }
        static void Optional3(Dog d = null) { }
        static void Optional4(string s = &quot;DEFAULT&quot;) { }

        static void Main()
        {
            Optional1();
            Optional2();
            Optional3();
        }
</pre></p>
<br />Filed under: <a href='http://csharp.2000things.com/category/methods/'>Methods</a> Tagged: <a href='http://csharp.2000things.com/tag/c/'>C#</a>, <a href='http://csharp.2000things.com/tag/constants/'>Constants</a>, <a href='http://csharp.2000things.com/tag/methods/'>Methods</a>, <a href='http://csharp.2000things.com/tag/optional-parameters/'>Optional Parameters</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/2000thingscsharp.wordpress.com/4956/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/2000thingscsharp.wordpress.com/4956/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/2000thingscsharp.wordpress.com/4956/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/2000thingscsharp.wordpress.com/4956/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/2000thingscsharp.wordpress.com/4956/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/2000thingscsharp.wordpress.com/4956/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/2000thingscsharp.wordpress.com/4956/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/2000thingscsharp.wordpress.com/4956/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/2000thingscsharp.wordpress.com/4956/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/2000thingscsharp.wordpress.com/4956/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/2000thingscsharp.wordpress.com/4956/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/2000thingscsharp.wordpress.com/4956/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/2000thingscsharp.wordpress.com/4956/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/2000thingscsharp.wordpress.com/4956/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=csharp.2000things.com&#038;blog=14273916&#038;post=4956&#038;subd=2000thingscsharp&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://csharp.2000things.com/2012/05/18/586-default-values-for-optional-parameters-must-be-constants/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8922e4d5254d602ba3ed32dd073b5a4e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">spsexton</media:title>
		</media:content>
	</item>
		<item>
		<title>#585 &#8211; Optional Parameters Must Come Last</title>
		<link>http://csharp.2000things.com/2012/05/17/585-optional-parameters-must-come-last/</link>
		<comments>http://csharp.2000things.com/2012/05/17/585-optional-parameters-must-come-last/#comments</comments>
		<pubDate>Thu, 17 May 2012 11:00:09 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Methods]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Optional Parameters]]></category>
		<category><![CDATA[Parameters]]></category>

		<guid isPermaLink="false">http://csharp.2000things.com/?p=4950</guid>
		<description><![CDATA[If you define a method that includes optional parameters, they must come after any required parameters.  This means that your options for required vs. optional parameters are: No parameters at all 1 or more required parameters (no default values) 1 or more optional parameters (with default values) 1 or more required parameters, followed by 1 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=csharp.2000things.com&#038;blog=14273916&#038;post=4950&#038;subd=2000thingscsharp&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you define a method that includes <a href="http://csharp.2000things.com/2012/05/16/584-defining-an-optional-parameter/">optional parameters</a>, they must come after any required parameters.  This means that your options for required vs. optional parameters are:</p>
<ul>
<li>No parameters at all</li>
<li>1 or more required parameters (no default values)</li>
<li>1 or more optional parameters (with default values)</li>
<li>1 or more required parameters, followed by 1 or more optional parameters</li>
</ul>
<p><pre class="brush: csharp;">
        static void NoParams() { }
        static void RequiredOnly(int x, int y) { }
        static void OptionalOnly(int x = 5, int y = 10) { }
        static void RequiredAndOptional(int x, int y, int a = 1, int b = 2) { }

        static void Main()
        {
            NoParams();
            RequiredOnly(5, 10);

            OptionalOnly();
            OptionalOnly(1);
            OptionalOnly(1, 2);

            RequiredAndOptional(1, 1);
            RequiredAndOptional(1, 2, 3);
            RequiredAndOptional(1, 2, 3, 4);
        }
</pre></p>
<br />Filed under: <a href='http://csharp.2000things.com/category/methods/'>Methods</a> Tagged: <a href='http://csharp.2000things.com/tag/c/'>C#</a>, <a href='http://csharp.2000things.com/tag/methods/'>Methods</a>, <a href='http://csharp.2000things.com/tag/optional-parameters/'>Optional Parameters</a>, <a href='http://csharp.2000things.com/tag/parameters/'>Parameters</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/2000thingscsharp.wordpress.com/4950/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/2000thingscsharp.wordpress.com/4950/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/2000thingscsharp.wordpress.com/4950/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/2000thingscsharp.wordpress.com/4950/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/2000thingscsharp.wordpress.com/4950/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/2000thingscsharp.wordpress.com/4950/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/2000thingscsharp.wordpress.com/4950/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/2000thingscsharp.wordpress.com/4950/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/2000thingscsharp.wordpress.com/4950/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/2000thingscsharp.wordpress.com/4950/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/2000thingscsharp.wordpress.com/4950/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/2000thingscsharp.wordpress.com/4950/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/2000thingscsharp.wordpress.com/4950/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/2000thingscsharp.wordpress.com/4950/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=csharp.2000things.com&#038;blog=14273916&#038;post=4950&#038;subd=2000thingscsharp&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://csharp.2000things.com/2012/05/17/585-optional-parameters-must-come-last/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8922e4d5254d602ba3ed32dd073b5a4e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">spsexton</media:title>
		</media:content>
	</item>
		<item>
		<title>#584 &#8211; Defining an Optional Parameter</title>
		<link>http://csharp.2000things.com/2012/05/16/584-defining-an-optional-parameter/</link>
		<comments>http://csharp.2000things.com/2012/05/16/584-defining-an-optional-parameter/#comments</comments>
		<pubDate>Wed, 16 May 2012 11:00:23 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Methods]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Optional Parameter]]></category>

		<guid isPermaLink="false">http://csharp.2000things.com/?p=4941</guid>
		<description><![CDATA[When you define a method in C#, you can define one or more of the method&#8217;s parameters as optional.  An optional parameter is one that has a default value, which allows a calling function to choose whether or not it wants to pass in a value for that parameter.  Any parameters that are omitted by [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=csharp.2000things.com&#038;blog=14273916&#038;post=4941&#038;subd=2000thingscsharp&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When you define a method in C#, you can define one or more of the method&#8217;s parameters as optional.  An optional parameter is one that has a default value, which allows a calling function to choose whether or not it wants to pass in a value for that parameter.  Any parameters that are omitted by the caller will take on the specified default value.</p>
<p>Here&#8217;s the <strong>Bark</strong> method of a <strong>Dog</strong> object, which supplies a default value for the <strong>numTimesToBark</strong> parameter, making it optional.</p>
<p><pre class="brush: csharp;">
        public void Bark(string barkSound, int numTimesToBark = 1)
        {
            for (int i = 0; i &lt; numTimesToBark; i++)
                Console.WriteLine(barkSound);
        }
</pre></p>
<p>When calling <strong>Dog.Bark</strong>, the caller can pass in a value for <strong>numTimesToBark</strong>, or leave off this argument so that the parameter uses the default value (1).</p>
<p><pre class="brush: csharp;">
// Pass in both barkSound and numTimesToBark
myDog.Bark(&quot;Bow-wow&quot;, 4);

// Pass in only barkSound
myDog.Bark(&quot;Woof&quot;);
</pre><br />
<a href="http://2000thingscsharp.files.wordpress.com/2012/05/584-001.png"><img class="alignnone size-full wp-image-4947" title="584-001" src="http://2000thingscsharp.files.wordpress.com/2012/05/584-001.png?w=630" alt=""   /></a></pre>
<br />Filed under: <a href='http://csharp.2000things.com/category/methods/'>Methods</a> Tagged: <a href='http://csharp.2000things.com/tag/c/'>C#</a>, <a href='http://csharp.2000things.com/tag/methods/'>Methods</a>, <a href='http://csharp.2000things.com/tag/optional-parameter/'>Optional Parameter</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/2000thingscsharp.wordpress.com/4941/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/2000thingscsharp.wordpress.com/4941/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/2000thingscsharp.wordpress.com/4941/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/2000thingscsharp.wordpress.com/4941/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/2000thingscsharp.wordpress.com/4941/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/2000thingscsharp.wordpress.com/4941/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/2000thingscsharp.wordpress.com/4941/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/2000thingscsharp.wordpress.com/4941/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/2000thingscsharp.wordpress.com/4941/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/2000thingscsharp.wordpress.com/4941/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/2000thingscsharp.wordpress.com/4941/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/2000thingscsharp.wordpress.com/4941/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/2000thingscsharp.wordpress.com/4941/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/2000thingscsharp.wordpress.com/4941/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=csharp.2000things.com&#038;blog=14273916&#038;post=4941&#038;subd=2000thingscsharp&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://csharp.2000things.com/2012/05/16/584-defining-an-optional-parameter/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8922e4d5254d602ba3ed32dd073b5a4e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">spsexton</media:title>
		</media:content>

		<media:content url="http://2000thingscsharp.files.wordpress.com/2012/05/584-001.png" medium="image">
			<media:title type="html">584-001</media:title>
		</media:content>
	</item>
		<item>
		<title>#583 &#8211; You Can&#8217;t Modify the Iterator Variable Within a foreach Loop</title>
		<link>http://csharp.2000things.com/2012/05/15/583-you-cant-modify-the-iterator-variable-within-a-foreach-loop/</link>
		<comments>http://csharp.2000things.com/2012/05/15/583-you-cant-modify-the-iterator-variable-within-a-foreach-loop/#comments</comments>
		<pubDate>Tue, 15 May 2012 11:00:28 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Basics]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[foreach]]></category>

		<guid isPermaLink="false">http://csharp.2000things.com/?p=4929</guid>
		<description><![CDATA[The iterator variable within a foreach loop is the variable that takes on the value of each item within the corresponding collection, each time through the loop. If you try to modify this iterator variable within the loop, however, you&#8217;ll get a compile-time error. Filed under: Basics Tagged: Basics, C#, foreach<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=csharp.2000things.com&#038;blog=14273916&#038;post=4929&#038;subd=2000thingscsharp&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The iterator variable within a <strong><a href="http://csharp.2000things.com/2010/11/19/155-iterating-through-an-array-using-the-foreach-statement/">foreach</a></strong><a href="http://csharp.2000things.com/2010/11/19/155-iterating-through-an-array-using-the-foreach-statement/"> loop</a> is the variable that takes on the value of each item within the corresponding collection, each time through the loop.</p>
<p><pre class="brush: csharp;">
            string[] puppets =
                {&quot;Crow T. Robot&quot;, &quot;Howdy Doody&quot;, &quot;Kermit&quot;,
                 &quot;King Friday XIII&quot;, &quot;Lamb Chop&quot;};

            // nextPuppet is the iterator variable
            foreach (string nextPuppet in puppets)
            {
                Console.WriteLine(&quot;Puppet: {0}&quot;, nextPuppet);
            }
</pre></p>
<p>If you try to modify this iterator variable within the loop, however, you&#8217;ll get a compile-time error.</p>
<p><pre class="brush: csharp;">
foreach (string nextPuppet in puppets)
{
    nextPuppet = &quot;(&quot; + nextPuppet + &quot;)&quot;;
    Console.WriteLine(&quot;Puppet: {0}&quot;, nextPuppet);
}
</pre></p>
<p><a href="http://2000thingscsharp.files.wordpress.com/2012/05/583-001.png"><img class="alignnone size-full wp-image-4935" title="583-001" src="http://2000thingscsharp.files.wordpress.com/2012/05/583-001.png?w=630" alt=""   /></a></p>
<br />Filed under: <a href='http://csharp.2000things.com/category/basics/'>Basics</a> Tagged: <a href='http://csharp.2000things.com/tag/basics/'>Basics</a>, <a href='http://csharp.2000things.com/tag/c/'>C#</a>, <a href='http://csharp.2000things.com/tag/foreach/'>foreach</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/2000thingscsharp.wordpress.com/4929/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/2000thingscsharp.wordpress.com/4929/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/2000thingscsharp.wordpress.com/4929/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/2000thingscsharp.wordpress.com/4929/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/2000thingscsharp.wordpress.com/4929/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/2000thingscsharp.wordpress.com/4929/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/2000thingscsharp.wordpress.com/4929/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/2000thingscsharp.wordpress.com/4929/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/2000thingscsharp.wordpress.com/4929/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/2000thingscsharp.wordpress.com/4929/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/2000thingscsharp.wordpress.com/4929/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/2000thingscsharp.wordpress.com/4929/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/2000thingscsharp.wordpress.com/4929/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/2000thingscsharp.wordpress.com/4929/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=csharp.2000things.com&#038;blog=14273916&#038;post=4929&#038;subd=2000thingscsharp&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://csharp.2000things.com/2012/05/15/583-you-cant-modify-the-iterator-variable-within-a-foreach-loop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8922e4d5254d602ba3ed32dd073b5a4e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">spsexton</media:title>
		</media:content>

		<media:content url="http://2000thingscsharp.files.wordpress.com/2012/05/583-001.png" medium="image">
			<media:title type="html">583-001</media:title>
		</media:content>
	</item>
		<item>
		<title>#582 &#8211; Use the as Operator to Unbox to a Nullable Type</title>
		<link>http://csharp.2000things.com/2012/05/14/582-use-the-as-operator-to-unbox-to-a-nullable-type/</link>
		<comments>http://csharp.2000things.com/2012/05/14/582-use-the-as-operator-to-unbox-to-a-nullable-type/#comments</comments>
		<pubDate>Mon, 14 May 2012 11:00:26 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Data Types]]></category>
		<category><![CDATA[as]]></category>
		<category><![CDATA[as operator]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Nullable]]></category>

		<guid isPermaLink="false">http://csharp.2000things.com/?p=4921</guid>
		<description><![CDATA[You can box regular value types or their equivalent nullable types (e.g. int and int?) and the boxed values will either be null or be of the underlying value type. You can unbox these values to a nullable type, or use the as operator to do the unboxing.  The example below shows the result of unboxing several different values [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=csharp.2000things.com&#038;blog=14273916&#038;post=4921&#038;subd=2000thingscsharp&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>You can box regular value types or their equivalent <a href="http://csharp.2000things.com/2012/05/11/581-boxing-and-unboxing-nullable-types/">nullable types</a> (e.g. <strong>int</strong> and <strong>int?</strong>) and the boxed values will either be null or be of the underlying value type.</p>
<p>You can unbox these values to a nullable type, or use the <strong>as </strong>operator to do the unboxing.  The example below shows the result of unboxing several different values to a nullable <strong>int</strong> (<strong>int?</strong>) using the <strong>as </strong>operator.</p>
<p><pre class="brush: csharp;">
int? i1 = null;   // Nullable&lt;int&gt; w/no value
int? i2 = 42;     // Nullable&lt;int&gt; with a value
int i3 = 12;      // Plain old int

// Boxing nullable types
object o1 = i1;
object o2 = i2;
object o3 = i3;
object o4 = new Dog(&quot;I'm not an int&quot;, 12);

// Unboxing to nullable types
int? ia1 = o1 as int?;    // null
int? ia2 = o2 as int?;    // 42
int? ia3 = o3 as int?;    // 12
int? ia4 = o4 as int?;    // null

bool bHasVal = ia1.HasValue;  // false
bHasVal = ia2.HasValue;       // true
bHasVal = ia3.HasValue;       // true
bHasVal = ia4.HasValue;       // false
</pre></p>
<br />Filed under: <a href='http://csharp.2000things.com/category/data-types/'>Data Types</a> Tagged: <a href='http://csharp.2000things.com/tag/as/'>as</a>, <a href='http://csharp.2000things.com/tag/as-operator/'>as operator</a>, <a href='http://csharp.2000things.com/tag/c/'>C#</a>, <a href='http://csharp.2000things.com/tag/data-types/'>Data Types</a>, <a href='http://csharp.2000things.com/tag/nullable/'>Nullable</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/2000thingscsharp.wordpress.com/4921/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/2000thingscsharp.wordpress.com/4921/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/2000thingscsharp.wordpress.com/4921/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/2000thingscsharp.wordpress.com/4921/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/2000thingscsharp.wordpress.com/4921/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/2000thingscsharp.wordpress.com/4921/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/2000thingscsharp.wordpress.com/4921/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/2000thingscsharp.wordpress.com/4921/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/2000thingscsharp.wordpress.com/4921/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/2000thingscsharp.wordpress.com/4921/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/2000thingscsharp.wordpress.com/4921/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/2000thingscsharp.wordpress.com/4921/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/2000thingscsharp.wordpress.com/4921/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/2000thingscsharp.wordpress.com/4921/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=csharp.2000things.com&#038;blog=14273916&#038;post=4921&#038;subd=2000thingscsharp&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://csharp.2000things.com/2012/05/14/582-use-the-as-operator-to-unbox-to-a-nullable-type/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8922e4d5254d602ba3ed32dd073b5a4e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">spsexton</media:title>
		</media:content>
	</item>
	</channel>
</rss>
