<?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>2Paths &#187; c#</title>
	<atom:link href="http://www.2paths.com/tag/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.2paths.com</link>
	<description>Custom Software Technical Architecture, Design and Development in Vancouver, BC, Canada</description>
	<lastBuildDate>Mon, 27 Sep 2010 01:15:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>C# features &#8211; LINQ primer</title>
		<link>http://www.2paths.com/2009/04/30/c-features-linq-primer/</link>
		<comments>http://www.2paths.com/2009/04/30/c-features-linq-primer/#comments</comments>
		<pubDate>Thu, 30 Apr 2009 19:04:32 +0000</pubDate>
		<dc:creator>Geoff</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Under the hood]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[newbies]]></category>

		<guid isPermaLink="false">http://www.2paths.com/?p=939</guid>
		<description><![CDATA[Language INtegrated Query (LINQ) adds extensions to the .NET framework which provide a domain specific language for querying and transforming collections right within C# (or VB for that matter). It provides syntax similar to other 4GL querying languages such as SQL, HQL or even OQL.
Below is a simple test case showing how to do LINQ [...]]]></description>
			<content:encoded><![CDATA[<p>Language INtegrated Query (<a href="http://msdn.microsoft.com/en-ca/library/bb308959.aspx">LINQ</a>) adds extensions to the .NET framework which provide a domain specific language for querying and transforming collections right within C# (or VB for that matter). It provides syntax similar to other 4GL querying languages such as SQL, HQL or even OQL.</p>
<p>Below is a simple test case showing how to do LINQ operations on a simple array:</p>
<pre class="brush: csharp">
        public void LinqArrayTest()
        {
            String[] names = { &quot;Burke&quot;, &quot;Connor&quot;, &quot;Frank&quot;,
                   &quot;Everett&quot;, &quot;Albert&quot;, &quot;George&quot;,
                   &quot;Harris&quot;, &quot;David&quot; };

            IEnumerable&lt;string&gt; query = from s in names
                               where s.Length == 5
                               orderby s
                               select s;

            List&lt;String&gt; results = query.ToList();

            Assert.AreEqual(3, results.Count);
            String[] expected = new String[] {&quot;Burke&quot;, &quot;David&quot;, &quot;Frank&quot;};
            for (int i = 0; i &lt; results.Count; i++)
            {
                Assert.AreEqual(expected[i], results.ElementAt(i));
            }
        }
</pre>
<p>It is also possible to create runtime LINQ queries using lambda expressions to qualify conditional logic:</p>
<pre class="brush: csharp">
        [TestMethod()]
        public void LinqLambdaTest()
        {
            String[] items = { &quot;cabbage&quot;, &quot;broccoli&quot;, &quot;carrot&quot;, &quot;parsnip&quot;, &quot;cauliflower&quot; };

            IEnumerable&lt;String&gt; query = items;

            // additive query generation using lambda expressions
            query = query.Where(item =&gt; item.StartsWith(&quot;c&quot;));
            query = query.Where(item =&gt; item.Length &lt; 8);
            query = query.OrderByDescending(item =&gt; item.ToLower());

            List&lt;String&gt; results = query.ToList();

            Assert.AreEqual(2, results.Count);
            String[] expected = { &quot;carrot&quot;, &quot;cabbage&quot; };
            for (int i = 0; i &lt; results.Count; i++)
            {
                Assert.AreEqual(expected[i], results.ElementAt(i));
            }
        }
</pre>
<p>LINQ provides a simple, generalised query framework for operating on data collections within the .NET stack. There are framework plugins to support LINQ backed by various datastore technologies, these include: <a href="http://msdn.microsoft.com/en-us/library/bb425822.aspx">LINQ to SQL</a>, <a href="http://msdn.microsoft.com/en-us/library/bb387098.aspx">LINQ to XML</a> and <a href="http://msdn.microsoft.com/en-us/library/bb386964.aspx">LINQ to Entities</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.2paths.com/2009/04/30/c-features-linq-primer/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>C# features &#8211; question mark syntax</title>
		<link>http://www.2paths.com/2009/04/28/c-features-question-mark-syntax/</link>
		<comments>http://www.2paths.com/2009/04/28/c-features-question-mark-syntax/#comments</comments>
		<pubDate>Tue, 28 Apr 2009 18:27:34 +0000</pubDate>
		<dc:creator>Geoff</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Under the hood]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[newbies]]></category>

		<guid isPermaLink="false">http://www.2paths.com/?p=919</guid>
		<description><![CDATA[Some recent project work in C# unearthed a few grains of syntactic sugar which I thought deserved a quick post. Not necessarily because they are ground breaking discoveries, but more because I found it difficult to find information via the usual channels (google) and wanted to share. I think the poor information discovery is a [...]]]></description>
			<content:encoded><![CDATA[<p>Some recent project work in C# unearthed a few grains of syntactic sugar which I thought deserved a quick post. Not necessarily because they are ground breaking discoveries, but more because I found it difficult to find information via the usual channels (google) and wanted to share. I think the poor information discovery is a result of said features being based on the question mark which is not an easy symbol to use for searches online.</p>
<h3>Single Question Mark &#8211; nullable types</h3>
<p>The single question mark syntax is somewhat obscure. Essentially it is short hand syntax for marking primitives as nullable. <code>System.Nullable</code> is a generic struct that is essentially a <a href="http://msdn.microsoft.com/en-us/library/1t3y8s4s(VS.80).aspx">wrapper to signify nullability</a>. This can be used as shown below:</p>
<pre class="brush: java">
// a nullable type for int
int? thing = 12;

// is syntactically equivalent to
System.Nullable&lt;int&gt; otherThing = 12;

// can be any valid int value OR null
thing = -12;
thing = null;

// usage
//y is set to zero
int y = thing.GetValueOrDefault();
// but this will throw an exception as thing.HasValue == false
y = thing.Value;
</pre>
<h3>Double Question Mark &#8211; non null assignment precedence</h3>
<p>This one is a little obscure but can be quite handy, it is very similar to certain assignment constructs in Perl as it allows one to use precedence to assign a variable from other potential variables and is a nice way to deal with default values.</p>
<pre class="brush: java">
String thing = null;
String defaultThing = &quot;nothing&quot;;

// standard trinary syntax
String otherThing = (thing != null) ? thing : defaultThing;

// syntactic sugar for the above
String sugaredThing = thing ?? defaultThing;

// can also chain things
otherThing = null;

// the first non-null value is the result of the assignment
String anotherThing = thing ?? otherThing ?? defaultThing;

// if all potentials are null, then the assignement is null)
anotherThing = thing ?? otherThing;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.2paths.com/2009/04/28/c-features-question-mark-syntax/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

