<?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/"
	>

<channel>
	<title>trentacular &#187; c#</title>
	<atom:link href="http://trentacular.com/category/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://trentacular.com</link>
	<description>Trent Foley's Spectacular Technical Blog</description>
	<lastBuildDate>Thu, 15 Apr 2010 21:32:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Extension Method of the Day: OrderBy with a Descending Flag</title>
		<link>http://trentacular.com/2010/02/extension-method-of-the-day-orderby-with-a-descending-flag/</link>
		<comments>http://trentacular.com/2010/02/extension-method-of-the-day-orderby-with-a-descending-flag/#comments</comments>
		<pubDate>Tue, 02 Feb 2010 23:52:16 +0000</pubDate>
		<dc:creator>Trent</dc:creator>
				<category><![CDATA[c#]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[collections]]></category>
		<category><![CDATA[extension method]]></category>
		<category><![CDATA[linq]]></category>

		<guid isPermaLink="false">http://trentacular.com/?p=241</guid>
		<description><![CDATA[The title should say it all.  Not sure why this didn&#8217;t make it into the System.Linq.Enumerable class, but this seems like a no-brainer.  You need to sort a collection, but whether you sort ascending or descending is determined by a boolean argument instead of having to call a different method for each scenario.  [...]]]></description>
			<content:encoded><![CDATA[<p>The title should say it all.  Not sure why this didn&#8217;t make it into the System.Linq.Enumerable class, but this seems like a no-brainer.  You need to sort a collection, but whether you sort ascending or descending is determined by a boolean argument instead of having to call a different method for each scenario.   Add this to your collection utilities class immediately:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Sorts the elements of a sequence according to a key.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;exception cref=&quot;System.ArgumentNullException&quot;&gt;source or keySelector is null.&lt;/exception&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;typeparam name=&quot;TSource&quot;&gt;The type of the elements of source.&lt;/typeparam&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;typeparam name=&quot;TKey&quot;&gt;The type of the key returned by keySelector.&lt;/typeparam&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;source&quot;&gt;A sequence of values to order.&lt;/param&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;keySelector&quot;&gt;A function to extract a key from an element.&lt;/param&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;descending&quot;&gt;if set to &lt;c&gt;true&lt;/c&gt;, sorts the elements in descending order; otherwise in ascending order.&lt;/param&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;returns&gt;An System.Linq.IOrderedEnumerable&lt;TElement&gt; whose elements are sorted according to a key.&lt;/returns&gt;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> IOrderedEnumerable<span style="color: #008000;">&lt;</span>TSource<span style="color: #008000;">&gt;</span> OrderBy<span style="color: #008000;">&lt;</span>TSource, TKey<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span> IEnumerable<span style="color: #008000;">&lt;</span>TSource<span style="color: #008000;">&gt;</span> source, Func<span style="color: #008000;">&lt;</span>TSource, TKey<span style="color: #008000;">&gt;</span> keySelector, <span style="color: #FF0000;">bool</span> descending<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>descending<span style="color: #000000;">&#41;</span>
                <span style="color: #0600FF;">return</span> source.<span style="color: #0000FF;">OrderByDescending</span><span style="color: #000000;">&#40;</span>keySelector<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">return</span> source.<span style="color: #0000FF;">OrderBy</span><span style="color: #000000;">&#40;</span>keySelector<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://trentacular.com/2010/02/extension-method-of-the-day-orderby-with-a-descending-flag/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
