<?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/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=i-love-firstordefault</link>
	<description></description>
	<lastBuildDate>Tue, 07 Feb 2012 23:42: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: Boris Juraga</title>
		<link>http://elegantcode.com/2008/09/23/i-love-firstordefault/comment-page-2/#comment-64411</link>
		<dc:creator>Boris Juraga</dc:creator>
		<pubDate>Sat, 12 Nov 2011 15:12:00 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2008/09/23/i-love-firstordefault/#comment-64411</guid>
		<description>So far i have had 1 trouble with it in .NET CF 3.5

List containing:
aaaaa
aabbb
abbcc
abccc
abcdd

var one = (from p in List where p.StartsWith(&quot;abcd&quot;) select p).FirstOrDefault();

one is null.

How is that possible?</description>
		<content:encoded><![CDATA[<p>So far i have had 1 trouble with it in .NET CF 3.5</p>
<p>List containing:<br />
aaaaa<br />
aabbb<br />
abbcc<br />
abccc<br />
abcdd</p>
<p>var one = (from p in List where p.StartsWith(&#8220;abcd&#8221;) select p).FirstOrDefault();</p>
<p>one is null.</p>
<p>How is that possible?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Zgraf</title>
		<link>http://elegantcode.com/2008/09/23/i-love-firstordefault/comment-page-2/#comment-64127</link>
		<dc:creator>Zgraf</dc:creator>
		<pubDate>Wed, 27 Jul 2011 16:56:00 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2008/09/23/i-love-firstordefault/#comment-64127</guid>
		<description>Rock on.  Thanks for explaining this with a clean, simple C# example.</description>
		<content:encoded><![CDATA[<p>Rock on.  Thanks for explaining this with a clean, simple C# example.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://elegantcode.com/2008/09/23/i-love-firstordefault/comment-page-1/#comment-63885</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Fri, 10 Jun 2011 05:57:00 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2008/09/23/i-love-firstordefault/#comment-63885</guid>
		<description>myTable.firstOrDefault

or myTable.Take(1).FirstOrDefault ? for select top 1 * from myTable </description>
		<content:encoded><![CDATA[<p>myTable.firstOrDefault</p>
<p>or myTable.Take(1).FirstOrDefault ? for select top 1 * from myTable </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Amila Rajapakse</title>
		<link>http://elegantcode.com/2008/09/23/i-love-firstordefault/comment-page-1/#comment-63845</link>
		<dc:creator>Amila Rajapakse</dc:creator>
		<pubDate>Sun, 22 May 2011 09:45:00 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2008/09/23/i-love-firstordefault/#comment-63845</guid>
		<description> love C# :)
</description>
		<content:encoded><![CDATA[<p> love C# <img src='http://elegantcode.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<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(&#8220;whatever&#8221;);<br />
or, if List.Find(T item) did not yet exist, return list.Contains(&#8220;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>
</channel>
</rss>

