<?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: I love FirstOrDefault</title>
	<atom:link href="http://elegantcode.com/2008/09/23/i-love-firstordefault/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com/2008/09/23/i-love-firstordefault/</link>
	<description></description>
	<lastBuildDate>Sun, 14 Mar 2010 20:36:31 -0500</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Code Monkey Labs</title>
		<link>http://elegantcode.com/2008/09/23/i-love-firstordefault/comment-page-1/#comment-33724</link>
		<dc:creator>Code Monkey Labs</dc:creator>
		<pubDate>Sun, 28 Sep 2008 03:47:49 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2008/09/23/i-love-firstordefault/#comment-33724</guid>
		<description>&lt;strong&gt;Weekly Web Nuggets #31...&lt;/strong&gt;

General Commented-Out Code &amp; Broken Windows : Jan Van Ryswyck says what everyone is thinking &#8211; commented code introduces a lot of mess into your code. There&#8217;s a reason we use version control systems&#8230;just delete that code! I Love ...</description>
		<content:encoded><![CDATA[<p><strong>Weekly Web Nuggets #31&#8230;</strong></p>
<p>General Commented-Out Code &amp; Broken Windows : Jan Van Ryswyck says what everyone is thinking &ndash; commented code introduces a lot of mess into your code. There&rsquo;s a reason we use version control systems&hellip;just delete that code! I Love &#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: J.P. Hamilton</title>
		<link>http://elegantcode.com/2008/09/23/i-love-firstordefault/comment-page-1/#comment-33412</link>
		<dc:creator>J.P. Hamilton</dc:creator>
		<pubDate>Wed, 24 Sep 2008 16:59:01 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2008/09/23/i-love-firstordefault/#comment-33412</guid>
		<description>Learn something new every day. I didn&#039;t know the method could take a lambda...guess I wasnt paying attention. I thought you had to do this:

return list.Where(blah blah).FirstOrDefault();

Nice.</description>
		<content:encoded><![CDATA[<p>Learn something new every day. I didn&#8217;t know the method could take a lambda&#8230;guess I wasnt paying attention. I thought you had to do this:</p>
<p>return list.Where(blah blah).FirstOrDefault();</p>
<p>Nice.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Reflective Perspective - Chris Alcock &#187; The Morning Brew #186</title>
		<link>http://elegantcode.com/2008/09/23/i-love-firstordefault/comment-page-1/#comment-33396</link>
		<dc:creator>Reflective Perspective - Chris Alcock &#187; The Morning Brew #186</dc:creator>
		<pubDate>Wed, 24 Sep 2008 06:59:46 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2008/09/23/i-love-firstordefault/#comment-33396</guid>
		<description>[...] I love FirstOrDefault - Chris Brandsma shows how Linq&#8217;s FirstOrDefault extension method can improve your code. [...]</description>
		<content:encoded><![CDATA[<p>[...] I love FirstOrDefault &#8211; Chris Brandsma shows how Linq&#8217;s FirstOrDefault extension method can improve your code. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jarod</title>
		<link>http://elegantcode.com/2008/09/23/i-love-firstordefault/comment-page-1/#comment-33377</link>
		<dc:creator>Jarod</dc:creator>
		<pubDate>Wed, 24 Sep 2008 00:08:26 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2008/09/23/i-love-firstordefault/#comment-33377</guid>
		<description>I think its important to point out that FirstOrDefault or SingleOrDefault are extension methods of IEnumerable, and Enumerate when called.

@Jamie

The example above is using List, so your arguments are fair. However, if you where working with IEnumerable, you would be forced to enumerate somehow before your example would work. (such as calling ToList()) 

In that case, FirstOrDefault does it all in one shot, is is much simpler, and doesnt force you to copy to the whole collection to a list when all you want is one object.</description>
		<content:encoded><![CDATA[<p>I think its important to point out that FirstOrDefault or SingleOrDefault are extension methods of IEnumerable, and Enumerate when called.</p>
<p>@Jamie</p>
<p>The example above is using List, so your arguments are fair. However, if you where working with IEnumerable, you would be forced to enumerate somehow before your example would work. (such as calling ToList()) </p>
<p>In that case, FirstOrDefault does it all in one shot, is is much simpler, and doesnt force you to copy to the whole collection to a list when all you want is one object.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jamie</title>
		<link>http://elegantcode.com/2008/09/23/i-love-firstordefault/comment-page-1/#comment-33366</link>
		<dc:creator>Jamie</dc:creator>
		<pubDate>Tue, 23 Sep 2008 21:38:06 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2008/09/23/i-love-firstordefault/#comment-33366</guid>
		<description>Example 1: return list.Count &gt; 0 ? list[0] : null;

Example 2: return list.Find(&quot;whatever&quot;); 
or, if List.Find(T item) did not yet exist, return list.Contains(&quot;whatever&quot;) ? &quot;whatever&quot; : null;

Are not all that worse than the FirstOrDefault code, are they?</description>
		<content:encoded><![CDATA[<p>Example 1: return list.Count &gt; 0 ? list[0] : null;</p>
<p>Example 2: return list.Find(&#8221;whatever&#8221;);<br />
or, if List.Find(T item) did not yet exist, return list.Contains(&#8221;whatever&#8221;) ? &#8220;whatever&#8221; : null;</p>
<p>Are not all that worse than the FirstOrDefault code, are they?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jason</title>
		<link>http://elegantcode.com/2008/09/23/i-love-firstordefault/comment-page-1/#comment-33364</link>
		<dc:creator>Jason</dc:creator>
		<pubDate>Tue, 23 Sep 2008 21:09:18 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2008/09/23/i-love-firstordefault/#comment-33364</guid>
		<description>Dang, trasa beat me to my comment.  I&#039;ve had one project in particular where SingleOrDefault() caught some false assumptions about a sproc.  On the other hand SingleOrDefault() doesn&#039;t return as soon as an item is found (on IEnumerable) so it might be slightly slower on large collections.  Not sure about the execution times of the two methods on LTS.  I&#039;m curious now, so I might check it out.

My personal favorite Linq extension methods are of the filtering and aggregate types.  I use list.Any(item =&gt; item.IsSomethingTrue) and list.Max(item =&gt; item.Property) a lot.</description>
		<content:encoded><![CDATA[<p>Dang, trasa beat me to my comment.  I&#8217;ve had one project in particular where SingleOrDefault() caught some false assumptions about a sproc.  On the other hand SingleOrDefault() doesn&#8217;t return as soon as an item is found (on IEnumerable) so it might be slightly slower on large collections.  Not sure about the execution times of the two methods on LTS.  I&#8217;m curious now, so I might check it out.</p>
<p>My personal favorite Linq extension methods are of the filtering and aggregate types.  I use list.Any(item =&gt; item.IsSomethingTrue) and list.Max(item =&gt; item.Property) a lot.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: trasa</title>
		<link>http://elegantcode.com/2008/09/23/i-love-firstordefault/comment-page-1/#comment-33358</link>
		<dc:creator>trasa</dc:creator>
		<pubDate>Tue, 23 Sep 2008 16:57:23 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2008/09/23/i-love-firstordefault/#comment-33358</guid>
		<description>I have caught bugs by using SingleOrDefault(), usually with comments around the usage like &quot;there can never be more than 1 Foo&#039;s matching in this collection,&quot;  (whoops)</description>
		<content:encoded><![CDATA[<p>I have caught bugs by using SingleOrDefault(), usually with comments around the usage like &#8220;there can never be more than 1 Foo&#8217;s matching in this collection,&#8221;  (whoops)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Colin Jack</title>
		<link>http://elegantcode.com/2008/09/23/i-love-firstordefault/comment-page-1/#comment-33357</link>
		<dc:creator>Colin Jack</dc:creator>
		<pubDate>Tue, 23 Sep 2008 16:30:49 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2008/09/23/i-love-firstordefault/#comment-33357</guid>
		<description>You read my mind, was thinking about how much I loved this little piece of code last week.</description>
		<content:encoded><![CDATA[<p>You read my mind, was thinking about how much I loved this little piece of code last week.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
