<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>.NET</title>
        <link>http://blog.colinmackay.net/category/16.aspx</link>
        <description>.NET</description>
        <language>en-GB</language>
        <copyright>Colin Angus Mackay</copyright>
        <managingEditor>colin.mackay@gmail.com</managingEditor>
        <generator>Subtext Version 1.9.0.27</generator>
        <item>
            <title>Tip of the Day #16: NaN (Not a Number)</title>
            <link>http://blog.colinmackay.net/archive/2009/09/12/Tip-of-the-Day-16-NaN-Not-a-Number.aspx</link>
            <description>&lt;h3&gt;&lt;/h3&gt;  &lt;h3&gt;The Issue&lt;/h3&gt;  &lt;p&gt;If you want to detect if a double (System.Double) or float (System.Single) is “not a number” or NaN you cannot use something like this:&lt;/p&gt;  &lt;pre&gt;if (myDouble == double.NaN) { /* do something */ }&lt;/pre&gt;

&lt;p&gt;It will always be false.&lt;/p&gt;

&lt;p&gt;Sounds crazy? Try this:&lt;/p&gt;

&lt;pre&gt;double myDouble = double.NaN;
Console.WriteLine("myDouble == double.NaN : {0}", myDouble == double.NaN);&lt;/pre&gt;

&lt;p&gt;The result is:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;myDouble == double.NaN : False&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can see that myDouble was explicitly set the value of double.NaN, yet in the next line it is returning false.&lt;/p&gt;

&lt;h3&gt;The Solution&lt;/h3&gt;

&lt;p&gt;If you want to test for a floating point value being Not a Number you to use IsNan() which is a static method on System.Double and System.Single. Here is the first example re-written to use the static method. It will now work correctly:&lt;/p&gt;

&lt;pre&gt;if (double.IsNan(myDouble) { /* do something */ }&lt;/pre&gt;

&lt;p&gt;If we re-write our other example:&lt;/p&gt;

&lt;pre&gt;double myDouble = double.NaN;
Console.WriteLine("double.IsNaN(myDouble) : {0}", double.IsNaN(myDouble));&lt;/pre&gt;

&lt;p&gt;We get the expected result too:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;double.IsNaN(myDouble) : True&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;The Reason&lt;/h3&gt;

&lt;p&gt;According to Wikipedia: &lt;em&gt;In &lt;/em&gt;&lt;a href="http://en.wikipedia.org/wiki/Computing"&gt;&lt;em&gt;computing&lt;/em&gt;&lt;/a&gt;&lt;em&gt;, &lt;b&gt;&lt;a href="http://en.wikipedia.org/wiki/NaN"&gt;NaN&lt;/a&gt;&lt;/b&gt;, which stands for &lt;b&gt;N&lt;/b&gt;ot &lt;b&gt;a&lt;/b&gt; &lt;b&gt;N&lt;/b&gt;umber, is a value or symbol that is usually produced as the result of an operation on invalid input operands, especially in &lt;/em&gt;&lt;a href="http://en.wikipedia.org/wiki/Floating_point"&gt;&lt;em&gt;floating-point&lt;/em&gt;&lt;/a&gt;&lt;em&gt; calculations. For example, most &lt;/em&gt;&lt;a href="http://en.wikipedia.org/wiki/Floating_point_unit"&gt;&lt;em&gt;floating-point units&lt;/em&gt;&lt;/a&gt;&lt;em&gt; are unable to explicitly calculate the square root of negative numbers, and will instead indicate that the operation was invalid and return a NaN result. NaNs may also be used to represent missing values in computations.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;It goes on to say: &lt;em&gt;A NaN does not compare equal to any floating-point number or NaN, even if the latter has an identical representation. One can therefore test whether a variable has a NaN value by comparing it to itself, thus if x = x gives false then x is a NaN code.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This is why (double.NaN == double.NaN) always results in false. And it is also how the .NET framework detects the NaN value in the IsNan() method.&lt;/p&gt;

&lt;pre&gt;public static bool IsNaN(double d) 
{ 
    return (&lt;a&gt;d&lt;/a&gt; != &lt;a&gt;d&lt;/a&gt;); 
}&lt;/pre&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:3609ff88-8c57-41ac-a86f-d2f45b1ff1f4" class="wlWriterEditableSmartContent"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/NaN" rel="tag"&gt;NaN&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Not+a+Number" rel="tag"&gt;Not a Number&lt;/a&gt;,&lt;a href="http://technorati.com/tags/C%23" rel="tag"&gt;C#&lt;/a&gt;,&lt;a href="http://technorati.com/tags/.NET" rel="tag"&gt;.NET&lt;/a&gt;,&lt;a href="http://technorati.com/tags/floating+point+numbers" rel="tag"&gt;floating point numbers&lt;/a&gt;,&lt;a href="http://technorati.com/tags/float" rel="tag"&gt;float&lt;/a&gt;,&lt;a href="http://technorati.com/tags/double" rel="tag"&gt;double&lt;/a&gt;,&lt;a href="http://technorati.com/tags/System.Single" rel="tag"&gt;System.Single&lt;/a&gt;,&lt;a href="http://technorati.com/tags/System.Double" rel="tag"&gt;System.Double&lt;/a&gt;&lt;/div&gt;&lt;img src="http://blog.colinmackay.net/aggbug/8988.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Colin Angus Mackay</dc:creator>
            <guid>http://blog.colinmackay.net/archive/2009/09/12/Tip-of-the-Day-16-NaN-Not-a-Number.aspx</guid>
            <pubDate>Sat, 12 Sep 2009 12:21:15 GMT</pubDate>
            <wfw:comment>http://blog.colinmackay.net/comments/8988.aspx</wfw:comment>
            <comments>http://blog.colinmackay.net/archive/2009/09/12/Tip-of-the-Day-16-NaN-Not-a-Number.aspx#feedback</comments>
            <slash:comments>9</slash:comments>
            <wfw:commentRss>http://blog.colinmackay.net/comments/commentRss/8988.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Tip of the day #13 (String Equality)</title>
            <link>http://blog.colinmackay.net/archive/2009/07/12/Tip-of-the-day-13-String-Comparison.aspx</link>
            <description>&lt;p&gt;When comparing two strings in a case insensitive manner, use:&lt;/p&gt;
&lt;pre&gt;myFirstString.Equals(mySecondString, StringComparison.InvariantCultureIgnoreCase)&lt;/pre&gt;
&lt;p&gt;or, if cultural rules are to be ignored completely* then use: &lt;/p&gt;
&lt;pre&gt;myFirstString.Equals(mySecondString, StringComparison.OrdinalIgnoreCase)&lt;/pre&gt;
&lt;p&gt;over: &lt;/p&gt;
&lt;pre&gt;myFirstString.ToLower() == mySecondString.ToLower()&lt;/pre&gt;
&lt;p&gt;&lt;small&gt;* The invariant culture is actually a non-region specific English language culture. The ordinal comparison is faster than any culture specific comparison as it uses a much simpler comparison algorithm.&lt;/small&gt;&lt;/p&gt;&lt;img src="http://blog.colinmackay.net/aggbug/8228.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Colin Angus Mackay</dc:creator>
            <guid>http://blog.colinmackay.net/archive/2009/07/12/Tip-of-the-day-13-String-Comparison.aspx</guid>
            <pubDate>Sun, 12 Jul 2009 11:19:05 GMT</pubDate>
            <wfw:comment>http://blog.colinmackay.net/comments/8228.aspx</wfw:comment>
            <comments>http://blog.colinmackay.net/archive/2009/07/12/Tip-of-the-day-13-String-Comparison.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://blog.colinmackay.net/comments/commentRss/8228.aspx</wfw:commentRss>
        </item>
        <item>
            <title>How to get a value from a text box into the database</title>
            <link>http://blog.colinmackay.net/archive/2009/06/12/How-to-get-a-value-from-a-text-box-into.aspx</link>
            <description>&lt;p&gt;This question was asked on a forum and I took some time to construct a reasonably lengthy reply so I’m copying it to my blog for a bit of permanence. &lt;/p&gt;  &lt;p&gt;I suspect that many of my regular readers will be dismayed at the lack of proper architecture (e.g. layering) but we all had to start somewhere and I suspect that your first programs were not properly layered or structured either. I know mine certainly weren’t. My aim with this was to show how a simple goal can be achieved, what basic things are needed and how to fit it all together by doing the simplest thing that would work (a mantra from the agile world).&lt;/p&gt;  &lt;p&gt;Here’s the post (slightly edited to put back some of the original context):&lt;/p&gt;  &lt;p&gt;Okay - Let's step back and show the whole thing from text box to database. NOTE: that this example shows everything in one place. This is generally considered poor practice, but as you are only just starting I'll not burden you with the principles of layered architecture and the single responsibility principle and so on. (Just be aware they exist and one day you'll have to learn about them)&lt;/p&gt;  &lt;p&gt;So, let's say you have a form with two text boxes, one for a name, and one for an age. Lets call them &lt;code&gt;NameTB &lt;/code&gt;and &lt;code&gt;AgeTB&lt;/code&gt;. The user can enter information in these text boxes and press a button that adds them to the database.&lt;/p&gt;  &lt;p&gt;First, we need to get the data from the text boxes into a form we can use.&lt;/p&gt;  &lt;pre&gt;string name = NameTB.Text;&lt;br /&gt;int age = Convert.ToInt32(AgeTB.Text);&lt;/pre&gt;

&lt;p&gt;Since text boxes only deal with strings we have to convert the string into a number (an Int32 - a 32bit integer) for the age value.&lt;/p&gt;

&lt;p&gt;Now, we need to set up the database connection and command in order to insert this. I'll assume you already have a &lt;a href="http://www.connectionstrings.com/"&gt;connections string&lt;/a&gt; to your database, I've called it &lt;code&gt;myConnectionString &lt;/code&gt;for this example.&lt;/p&gt;

&lt;pre&gt;SqlConnection myConnection = new SqlConnection(myConnectionString);&lt;br /&gt;SqlCommand myCommand = new SqlCommand("INSERT Person(NameField, AgeField) "+&lt;br /&gt;    VALUES (@nameParam, @ageParam)", myConnection);&lt;/pre&gt;
I've now set up the SQL Command with an insert statement. I've assumed there is a table called &lt;code&gt;Person &lt;/code&gt;and it has two columns called &lt;code&gt;NameField &lt;/code&gt;and &lt;code&gt;AgeField&lt;/code&gt;. I'm also going to insert the values via parameters, which I've indicated with &lt;code&gt;@nameParam&lt;/code&gt; and &lt;code&gt;@ageParam&lt;/code&gt;. SQL Server requires that all parameter names start with an @ symbol. Other databases may vary. 

&lt;pre&gt;myCommand.Parameters.AddWithValue("@nameParam", name);&lt;br /&gt;myCommand.Parameters.AddWithValue("@ageParam", age);&lt;/pre&gt;
We've now added the parameters into the SQL command and we've given each parameter the value we got earlier. Finally: 

&lt;pre&gt;myConnection.Open();&lt;br /&gt;myComment.ExecuteNonQuery();&lt;br /&gt;myConnection.Close();&lt;/pre&gt;

&lt;p&gt;This opens the connection, runs the INSERT statement and closes the connection again. We're using &lt;code&gt;ExecuteNonQuery &lt;/code&gt;because we don't expect any results back from SQL Server. If we were expecting data back (e.g. because we were using a SELECT statement) we could use ExecuteReader (for many rows/columns) or ExecuteScalar (for a single value).&lt;/p&gt;

&lt;p&gt;This is a very basic example. I’ve not shown any error checking or exception handling. There is also the implicit assumption that all this code resides inside a button click event, which is considered poor practice for anything but a small or throw away application.&lt;/p&gt;&lt;img src="http://blog.colinmackay.net/aggbug/7856.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Colin Angus Mackay</dc:creator>
            <guid>http://blog.colinmackay.net/archive/2009/06/12/How-to-get-a-value-from-a-text-box-into.aspx</guid>
            <pubDate>Fri, 12 Jun 2009 22:39:45 GMT</pubDate>
            <wfw:comment>http://blog.colinmackay.net/comments/7856.aspx</wfw:comment>
            <comments>http://blog.colinmackay.net/archive/2009/06/12/How-to-get-a-value-from-a-text-box-into.aspx#feedback</comments>
            <wfw:commentRss>http://blog.colinmackay.net/comments/commentRss/7856.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Dynamic Objects in C# 4.0</title>
            <link>http://blog.colinmackay.net/archive/2009/06/04/Dynamic-Objects-in-C-4.0.aspx</link>
            <description>&lt;p&gt;It seems only very recently that I was posting about this wonderful new feature in C# 3.0 called LINQ and its associated language features such as anonymous types, object initialisers and lambda expressions. Soon C#4.0 will be released and it has a host of new goodies to look forward to.&lt;/p&gt;
&lt;p&gt;So far I’ve just been dabbling with dynamic types and the dynamic keyword.&lt;/p&gt;
&lt;p&gt;C# has been up until this point a statically bound language. That meant that if the compiler couldn’t find the method to bind to then it wasn’t going to compile the application. Other languages, such as &lt;a href="http://en.wikipedia.org/wiki/Ruby_(programming_language)"&gt;Ruby&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/IronPython"&gt;IronPython&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Magik_(programming_language"&gt;Magik&lt;/a&gt; and &lt;a href="http://ironsmalltalk.codeplex.com/"&gt;IronSmalltalk&lt;/a&gt; are all dynamically (or late) bound where the decision about where a method call ends up is taken at runtime.&lt;/p&gt;
&lt;p&gt;Now if you declare an object as being dynamic the compiler will hold off, just as it would do naturally in a dynamic language. The method need not exist until runtime. The binding happens at runtime. &lt;a title="SnagIt Capture by Colin  Angus Mackay, on Flickr" href="http://www.flickr.com/photos/colinangusmackay/3592789465/"&gt;&lt;img style="BORDER-RIGHT-WIDTH: 0px; MARGIN: 0px 10px 0px 15px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" border="0" alt="SnagIt Capture" align="right" width="415" height="142" src="http://farm4.static.flickr.com/3323/3592789465_f29002f4f0_o.png" /&gt;&lt;/a&gt;If, like me, you rely heavily on intellisense to figure out if you are doing the right thing then you are going to have to get used to not having it. Since the call will be bound at runtime the compiler (and of course intellisense) won’t know whether a binding is valid or not. So, instead of regular intellisense you get a message simply saying “(dyanmic expression) This operation will be resolved at runtime.”&lt;/p&gt;
&lt;p&gt;So, how do you get started with dynamic objects? I suppose the simplest example would be an object graph that is built at runtime that would normally have a fairly dynamic structure, say a nice XML file.&lt;/p&gt;
&lt;p&gt;In this example, I’m going to take an XElement object (introduced in .NET 3.5) and wrap it in a new object type I’m creating called DynamicElement. This will inherit from DynamicObject (in the System.Dynamic namespace) which provides various bits of functionality that allows late binding.&lt;/p&gt;
&lt;pre&gt;using System.Dynamic;
using System.Linq;
using System.Xml.Linq;

namespace ColinAngusMackay.DynamicXml
{
    public class DynamicElement : DynamicObject
    {
        private XElement actualElement;

        public DynamicElement(XElement actualElement)
        {
            this.actualElement = actualElement;
        }

        public override bool TryGetMember(GetMemberBinder binder, 
            out object result)
        {
            string name = binder.Name;

            var elements = actualElement.Elements(name);

            int numElements = elements.Count();
            if (numElements == 0)
                return base.TryGetMember(binder, out result);
            if (numElements == 1)
            {
                result = new DynamicElement(elements.First());
                return true;
            }

            result = from e in elements select new DynamicElement(e);
            return true;
        }

        public override string ToString()
        {
            return actualElement.Value;
        }
    }
}&lt;/pre&gt;
&lt;p&gt;The key method in this class is the override of the TryGetMember method. Everytime the runtime needs to resolve a method call it will call this method to work out what it needs to do.&lt;/p&gt;
&lt;p&gt;In this example, all that happens is that if the name matches the name of a child element in the XML then that child element is returned. If there are multiple child elements with the same name then an enumerable collection of child elements is returned.&lt;/p&gt;
&lt;p&gt;&lt;a title="SnagIt Capture by Colin  Angus Mackay, on Flickr" href="http://www.flickr.com/photos/colinangusmackay/3593700640/"&gt;&lt;img style="BORDER-RIGHT-WIDTH: 0px; MARGIN: 0px 10px 0px 15px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" border="0" alt="SnagIt Capture" align="right" width="496" height="154" src="http://farm3.static.flickr.com/2472/3593700640_21364068e1_o.png" /&gt;&lt;/a&gt;In the event that there is no match the method defers to the base class. If the binding fails then a RuntimeBinderException is thrown. &lt;/p&gt;
&lt;p&gt;However, if the binding works you can make complex or ugly calls look much easier. For example. This program using the DynamicElement class to read the contents of an RSS feed:&lt;/p&gt;
&lt;pre&gt;using System;
using System.Xml.Linq;
using ColinAngusMackay.DynamicXml;

namespace ConsoleRunner
{
    class Program
    {
        static void Main(string[] args)
        {
            XElement xel = XElement.Parse(SampleXml.RssFeed);
            dynamic del = new DynamicElement(xel);

            Console.WriteLine(del.channel.title);
            Console.WriteLine(del.channel.description);

            foreach (dynamic item in del.channel.item)
                Console.WriteLine(item.title);

            Console.ReadLine();
        }
    }
}&lt;/pre&gt;
&lt;p&gt;The program starts off by reading in some XML into a regular XElement object. It it then wrapped up into the DynamicElement object, del.&lt;/p&gt;
&lt;p&gt;The variable del is declared as a dynamic which lets compiler know that calls to its members will be resolved at runtime.&lt;/p&gt;
&lt;p&gt;The program then uses the dynamic object to very easily navigate the XML. In this example, I’ve used the XML of the RSS feed for my blog.&lt;/p&gt;
&lt;p&gt;The output of the program is:&lt;/p&gt;
&lt;p&gt;&lt;a title="SnagIt Capture by Colin  Angus Mackay, on Flickr" href="http://www.flickr.com/photos/colinangusmackay/3592955661/"&gt;&lt;img style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: block; FLOAT: none; MARGIN-LEFT: auto; BORDER-TOP: 0px; MARGIN-RIGHT: auto; BORDER-RIGHT: 0px" border="0" alt="SnagIt Capture" width="533" height="179" src="http://farm4.static.flickr.com/3367/3592955661_01c9bd2805_o.png" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;The barrier to entry for creating and using dynamic objects is quite low. It will be quite interesting to see how this new feature plays out.&lt;/p&gt;
&lt;p&gt;Many people like the additional comfort that static binding at compile time provides as it means less things to go wrong at compile time. Advocates of dynamic binding often argue that if you are doing TDD then the tests will ensure that the application is running correctly.&lt;/p&gt;
&lt;p&gt;Of course, dynamic binding, like any other language features, is open to abuse. I fully expect to see on forums examples of people who are using it quite wrongly and getting themselves into a terrible pickle as a result. This does not mean that dynamic objects are bad, it just means programmers need to learn how to use the tools they have correctly.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Caveat Programmator: This blog post is based on early preliminary information using Visual Studio 2010 / .NET Framework 4.0 Beta 1&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;&lt;img src="http://blog.colinmackay.net/aggbug/7751.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Colin Angus Mackay</dc:creator>
            <guid>http://blog.colinmackay.net/archive/2009/06/04/Dynamic-Objects-in-C-4.0.aspx</guid>
            <pubDate>Thu, 04 Jun 2009 00:19:46 GMT</pubDate>
            <wfw:comment>http://blog.colinmackay.net/comments/7751.aspx</wfw:comment>
            <comments>http://blog.colinmackay.net/archive/2009/06/04/Dynamic-Objects-in-C-4.0.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://blog.colinmackay.net/comments/commentRss/7751.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Rant of the day: IDisposable</title>
            <link>http://blog.colinmackay.net/archive/2009/04/28/Rant-of-the-day-IDisposable.aspx</link>
            <description>&lt;p&gt;My colleagues are probably used to the fact that I rant about code quality frequently. I take code quality very seriously. Not because I'm especially expert in it, but because features of basic code quality make it easier for other people to read and maintain the code. &lt;/p&gt;  &lt;p&gt;Today's irritation comes from some code (replicated in a number of classes I might add) that implements IDisposable. It is a fine interface and by implementing it you are telling the rest of the world that you have some stuff that can't just be left to the garbage collector to clean up. These are things like file streams, database connections, etc. Any type of scarce resource that you want to hand back as soon as you are finished with it rather than leave it up to the garbage collector.&lt;/p&gt;  &lt;p&gt;However, I came across this "gem" in some code today where the class, basically a utility class, contained no fields (so it wasn't holding on to anything at all, let alone anything that might be a scarce resource). Yet, for some reason it implemented IDisposable. What was it going to dispose? What could it dispose?&lt;/p&gt;  &lt;p&gt;The answer was in the code:&lt;/p&gt;  &lt;pre&gt;public void Dispose()
{
    // Nothing to dispose of.
}&lt;/pre&gt;

&lt;p&gt;Quite!&lt;/p&gt;&lt;img src="http://blog.colinmackay.net/aggbug/7330.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Colin Angus Mackay</dc:creator>
            <guid>http://blog.colinmackay.net/archive/2009/04/28/Rant-of-the-day-IDisposable.aspx</guid>
            <pubDate>Tue, 28 Apr 2009 18:35:30 GMT</pubDate>
            <wfw:comment>http://blog.colinmackay.net/comments/7330.aspx</wfw:comment>
            <comments>http://blog.colinmackay.net/archive/2009/04/28/Rant-of-the-day-IDisposable.aspx#feedback</comments>
            <slash:comments>4</slash:comments>
            <wfw:commentRss>http://blog.colinmackay.net/comments/commentRss/7330.aspx</wfw:commentRss>
        </item>
        <item>
            <title>The StackOverflowException</title>
            <link>http://blog.colinmackay.net/archive/2009/03/28/The-StackOverflowException.aspx</link>
            <description>&lt;p&gt;Take a look at the following code:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Program
&lt;/span&gt;{
    &lt;span style="color: blue"&gt;static void &lt;/span&gt;Main(&lt;span style="color: blue"&gt;string&lt;/span&gt;[] args)
    {
        &lt;span style="color: blue"&gt;try
        &lt;/span&gt;{
            RecurseForever();
        }
        &lt;span style="color: blue"&gt;catch &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;StackOverflowException&lt;/span&gt;)
        {
            &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;"Caught Stack Overflow Exception"&lt;/span&gt;);
        }
        &lt;span style="color: blue"&gt;catch &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;Exception&lt;/span&gt;)
        {
            &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;"Caught general Exception"&lt;/span&gt;);
        }

        &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.ReadLine();
    }

    &lt;span style="color: blue"&gt;static void &lt;/span&gt;RecurseForever()
    {
        RecurseForever();
    }
}&lt;/pre&gt;

&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;What do you think the output of the program will be?&lt;/p&gt;

&lt;p&gt;If you had asked me a few days ago I'd have said the output would be "Caught Stack Overflow Exception", however that isn't the case. If you run the code in the debugger this is what you actually get:&lt;/p&gt;

&lt;p&gt;&lt;a title="StackOverflowException by Colin  Angus Mackay, on Flickr" href="http://www.flickr.com/photos/colinangusmackay/3341673987/"&gt;&lt;img height="343" alt="StackOverflowException" src="http://farm4.static.flickr.com/3552/3341673987_8eeb9afd14_o.png" width="596" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The exception simply isn't caught. &lt;/p&gt;

&lt;p&gt;If the application isn't being debugged it will simply end at this point. It goes directly to jail. It does not pass GO. It does not collect £200.&lt;/p&gt;

&lt;p&gt;&lt;a title="ConsoleApplication2 has stopped working by Colin  Angus Mackay, on Flickr" href="http://www.flickr.com/photos/colinangusmackay/3391198076/"&gt;&lt;img height="183" alt="ConsoleApplication2 has stopped working" src="http://farm4.static.flickr.com/3651/3391198076_1573589921_o.png" width="376" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blog.colinmackay.net/aggbug/7049.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Colin Angus Mackay</dc:creator>
            <guid>http://blog.colinmackay.net/archive/2009/03/28/The-StackOverflowException.aspx</guid>
            <pubDate>Sat, 28 Mar 2009 00:14:41 GMT</pubDate>
            <wfw:comment>http://blog.colinmackay.net/comments/7049.aspx</wfw:comment>
            <comments>http://blog.colinmackay.net/archive/2009/03/28/The-StackOverflowException.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://blog.colinmackay.net/comments/commentRss/7049.aspx</wfw:commentRss>
        </item>
        <item>
            <title>ASP.NET MVC Framework Preview - A review</title>
            <link>http://blog.colinmackay.net/archive/2008/12/28/5565.aspx</link>
            <description>&lt;p&gt;I've just finished reading &lt;a href="http://blog.codeville.net/" target="_blank"&gt;Steven Sanderson's&lt;/a&gt; book &lt;a href="http://www.apress.com/book/view/9781430216469" target="_blank"&gt;ASP.NET MVC Framework Preview&lt;/a&gt; published by &lt;a href="http://www.apress.com/" target="_blank"&gt;APress&lt;/a&gt;. While the book was short I felt it did give me a bit of an introduction to &lt;a href="http://www.asp.net/mvc/" target="_blank"&gt;ASP.NET MVC&lt;/a&gt;. Although I have to admit that I could have probably got that from reading a number of articles.&lt;/p&gt;  &lt;p&gt;The book is split in to a number of areas that could be summarised as Why? How? and Where? The Why? (chapter 1) describes why you would want to use &lt;a href="http://www.asp.net/mvc/" target="_blank"&gt;ASP.NET MVC&lt;/a&gt; over traditional ASP.NET*. The How? (chapter 2) describes how you would create a web application with &lt;a href="http://www.asp.net/mvc/" target="_blank"&gt;ASP.NET MVC&lt;/a&gt; and the Where? (chapter 3) describes the other architecture that ASP.NET MVC fits in with. Then, finally, there is an appendix that describes some of the new language features of C# 3.0 and I felt that this was added just to try and bulk the book out a little bit.&lt;/p&gt;  &lt;p&gt;I have to admit that when I first opened the package containing the book I was a little disappointed by the size. When I opened the book I was more disappointed when I saw that, conversely, the font size was larger than I was expecting too.&lt;/p&gt;  &lt;p&gt;If you already have an idea that you want to use &lt;a href="http://www.asp.net/mvc/" target="_blank"&gt;ASP.NET MVC&lt;/a&gt; and why then chapter 1 can easily be skipped. If you are already familiar with &lt;a href="http://en.wikipedia.org/wiki/N-tier" target="_blank"&gt;n-tier&lt;/a&gt; development, &lt;a href="http://en.wikipedia.org/wiki/Object-relational_mapping" target="_blank"&gt;ORM&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Inversion_of_Control" target="_blank"&gt;IoC&lt;/a&gt;, &lt;a href="http://www.testdriven.com" target="_blank"&gt;unit testing&lt;/a&gt; and so on then chapter 3 can be skimmed quite quickly. That leaves the real meat of the book just in the 30 pages that is chapter 2.&lt;/p&gt;  &lt;p&gt;Despite all the negative things that I have said up to this point, I rather like Steven's writing style. It is clear and and easy to follow. There are a fair number of footnotes for clarification or to point you off in the direction of more information that is outside the scope of the book. He's given enough information that a person could confidently make a stab at creating a starter application using ASP.NET MVC without too much trouble.&lt;/p&gt;  &lt;p&gt;In short, I'm looking forward to &lt;a href="http://blog.codeville.net/" target="_blank"&gt;Steven Sanderson's&lt;/a&gt; 500 page and hopefully much more in depth &lt;a href="http://apress.com/book/view/9781430210078" target="_blank"&gt;Pro ASP.NET MVC&lt;/a&gt; book coming out in January 2009.&lt;/p&gt;  &lt;p&gt;* I think this is where terminology is going to get slightly confusing. We already talk about "Classic ASP" when referring to ASP as it was before .NET came along. Now we have "Traditional ASP.NET" to refer to ASP.NET before MVC. Of course, traditional ASP.NET isn't going away, just as the traditional songs I was taught at school haven't gone away just because a bunch of rock-stars have come along and created new songs. (I was going to say pop-stars, then I realised they don't tend to write their own songs these days)&lt;/p&gt;  &lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:d832d479-2018-4228-8118-a68ff54c4ca4" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/ASP.NET%20MVC" rel="tag"&gt;ASP.NET MVC&lt;/a&gt;,&lt;a href="http://technorati.com/tags/MCV" rel="tag"&gt;MCV&lt;/a&gt;,&lt;a href="http://technorati.com/tags/APress" rel="tag"&gt;APress&lt;/a&gt;,&lt;a href="http://technorati.com/tags/book%20review" rel="tag"&gt;book review&lt;/a&gt;&lt;/div&gt;&lt;img src="http://blog.colinmackay.net/aggbug/5565.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Colin Angus Mackay</dc:creator>
            <guid>http://blog.colinmackay.net/archive/2008/12/28/5565.aspx</guid>
            <pubDate>Sun, 28 Dec 2008 19:56:39 GMT</pubDate>
            <wfw:comment>http://blog.colinmackay.net/comments/5565.aspx</wfw:comment>
            <comments>http://blog.colinmackay.net/archive/2008/12/28/5565.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://blog.colinmackay.net/comments/commentRss/5565.aspx</wfw:commentRss>
        </item>
        <item>
            <title>New article on Code Project</title>
            <link>http://blog.colinmackay.net/archive/2008/12/06/5133.aspx</link>
            <description>&lt;p&gt;It has taken a while, but I finally got around to putting another article up on &lt;a href="http://www.codeproject.com/" target="_blank"&gt;Code Project&lt;/a&gt;. The article is based on a series of blog posts (&lt;a href="http://blog.colinmackay.net/archive/2008/10/13/4271.aspx" target="_blank"&gt;Finding things with Virtual Earth&lt;/a&gt;, &lt;a href="http://blog.colinmackay.net/archive/2008/10/17/4296.aspx" target="_blank"&gt;Using PushPins with the Virtual Earth ASP.NET control&lt;/a&gt;, and &lt;a href="http://blog.colinmackay.net/archive/2008/10/26/4403.aspx" target="_blank"&gt;Drawing lines on the map with the Virtual Earth ASP.NET control&lt;/a&gt;) that I wrote on the subject on &lt;a href="http://dev.live.com/tools/" target="_blank"&gt;ASP.NET Controls for Virtual Earth&lt;/a&gt;. However, it is updated and includes extra information on Polygons that wasn't in my original blog post series.&lt;/p&gt;  &lt;p&gt;You can find the article here: &lt;a title="http://www.codeproject.com/KB/webforms/data_visualisation_ve.aspx" href="http://www.codeproject.com/KB/webforms/data_visualisation_ve.aspx"&gt;Data Visualisation with Virtual Earth ASP.NET Controls&lt;/a&gt;&lt;/p&gt;  &lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:3263cf7d-5794-43ed-8e04-957666170aeb" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/Virtual%20Earth" rel="tag"&gt;Virtual Earth&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Code%20Project" rel="tag"&gt;Code Project&lt;/a&gt;,&lt;a href="http://technorati.com/tags/.NET" rel="tag"&gt;.NET&lt;/a&gt;,&lt;a href="http://technorati.com/tags/ASP.NET" rel="tag"&gt;ASP.NET&lt;/a&gt;&lt;/div&gt;&lt;img src="http://blog.colinmackay.net/aggbug/5133.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Colin Angus Mackay</dc:creator>
            <guid>http://blog.colinmackay.net/archive/2008/12/06/5133.aspx</guid>
            <pubDate>Sat, 06 Dec 2008 17:40:02 GMT</pubDate>
            <wfw:comment>http://blog.colinmackay.net/comments/5133.aspx</wfw:comment>
            <comments>http://blog.colinmackay.net/archive/2008/12/06/5133.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://blog.colinmackay.net/comments/commentRss/5133.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Formatting dates the hard way</title>
            <link>http://blog.colinmackay.net/archive/2008/12/02/5048.aspx</link>
            <description>&lt;p&gt;I was doing a bit of a code review and I spotted this in the code base.&lt;/p&gt;  &lt;blockquote&gt;   &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;string&lt;/span&gt;[] splitOptions = &lt;span style="color: blue"&gt;new string&lt;/span&gt;[1] { dayEarlier.Date.Year.ToString() };
&lt;span style="color: blue"&gt;string&lt;/span&gt;[] earlyDates = dayEarlier.Date.GetDateTimeFormats();
&lt;span style="color: blue"&gt;string&lt;/span&gt;[] earlySplit = earlyDates[67].Split(splitOptions, &lt;span style="color: #2b91af"&gt;StringSplitOptions&lt;/span&gt;.RemoveEmptyEntries);
earlySplit[0] = earlySplit[0].Replace(&lt;span style="color: #a31515"&gt;","&lt;/span&gt;, &lt;span style="color: blue"&gt;string&lt;/span&gt;.Empty);&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Essentially the code gets the date in a specific format. However, it does it in the oddest most convoluted way I’ve ever seen.  Just to explain, here is the code again but this time I've added some comments:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="code"&gt;&lt;span style="color: green"&gt;// dayEarlier is a business object with a property called Date that returns a DateTime.
// splitOptions will contain the year in an 1-element string array.
&lt;/span&gt;&lt;span style="color: blue"&gt;string&lt;/span&gt;[] splitOptions = &lt;span style="color: blue"&gt;new string&lt;/span&gt;[1] { dayEarlier.Date.Year.ToString() };

&lt;span style="color: green"&gt;// earlyDates will contain the dayEarlier Date in umpteen different formats.
&lt;/span&gt;&lt;span style="color: blue"&gt;string&lt;/span&gt;[] earlyDates = dayEarlier.Date.GetDateTimeFormats();

&lt;span style="color: green"&gt;// earlySplit will contain the 68th (!) formatted date (out of 89 that get generated). 
// Element 0 in this array will contain the bit upto the year, element 1 will contain 
// the bit after the year. The year itself is discarded.
&lt;/span&gt;&lt;span style="color: blue"&gt;string&lt;/span&gt;[] earlySplit = earlyDates[67].Split(splitOptions, &lt;span style="color: #2b91af"&gt;StringSplitOptions&lt;/span&gt;.RemoveEmptyEntries);

&lt;span style="color: green"&gt;// The first element (element 0) of earlySplit is then modified to remove the comma.
&lt;/span&gt;earlySplit[0] = earlySplit[0].Replace(&lt;span style="color: #a31515"&gt;","&lt;/span&gt;, &lt;span style="color: blue"&gt;string&lt;/span&gt;.Empty);&lt;/pre&gt;
&lt;/blockquote&gt;

&lt;p&gt;In short, what is actually being looked for is the day name, day of the month and the month. That’s it. And that, apparently, isn’t even in the 89 permutations of the date that .NET generated in the second line of code. To add to the potential problems with this, I've not seen any documentation that states that the permutations given by this method will stay the same.&lt;/p&gt;

&lt;p&gt;All this code could easily be re-written simply as:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="code"&gt;dayEarlier.Date.ToString(&lt;span style="color: #a31515"&gt;"ddd dd MMM"&lt;/span&gt;);&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;And the bonus here is that we are not generating 88 completely useless permutations, nor are we generating the permutation that is simply the closest match that we still have to futz around with. We are generating the date in exactly the format that we want. (Current culture permitting)&lt;/p&gt;

&lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:90079063-ee8a-4bc4-90e5-77dda0da8699" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/C#" rel="tag"&gt;C#&lt;/a&gt;,&lt;a href="http://technorati.com/tags/DateTime" rel="tag"&gt;DateTime&lt;/a&gt;,&lt;a href="http://technorati.com/tags/ToString" rel="tag"&gt;ToString&lt;/a&gt;,&lt;a href="http://technorati.com/tags/date%20format" rel="tag"&gt;date format&lt;/a&gt;,&lt;a href="http://technorati.com/tags/.NET" rel="tag"&gt;.NET&lt;/a&gt;&lt;/div&gt;&lt;img src="http://blog.colinmackay.net/aggbug/5048.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Colin Angus Mackay</dc:creator>
            <guid>http://blog.colinmackay.net/archive/2008/12/02/5048.aspx</guid>
            <pubDate>Tue, 02 Dec 2008 20:03:25 GMT</pubDate>
            <wfw:comment>http://blog.colinmackay.net/comments/5048.aspx</wfw:comment>
            <comments>http://blog.colinmackay.net/archive/2008/12/02/5048.aspx#feedback</comments>
            <slash:comments>3</slash:comments>
            <wfw:commentRss>http://blog.colinmackay.net/comments/commentRss/5048.aspx</wfw:commentRss>
        </item>
        <item>
            <title>An Introduction to ASP.NET MVC</title>
            <link>http://blog.colinmackay.net/archive/2008/09/24/4076.aspx</link>
            <description>&lt;p&gt;&lt;strong&gt;[&lt;/strong&gt;&lt;strong&gt;&lt;a href="http://www.eventbrite.com/event/176356487/camblog" target="_blank"&gt;More details and registration&lt;/a&gt;&lt;/strong&gt;&lt;strong&gt;]&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;16th October 2008 at 19:00 in Edinburgh&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Today, ASP.NET webforms is a well established and highly productive platform for building web applications. Some people though, crave more control. They want to operate that bit closer to the metal, enjoy a clear separation of concerns and ensure that unit testing their application is made as easy as possible. &lt;/p&gt;  &lt;p&gt;Enter &lt;a href="http://www.asp.net/mvc/"&gt;ASP.NET MVC&lt;/a&gt;. ASP.NET MVC enables you to build &lt;a href="http://en.wikipedia.org/wiki/Model-view-controller"&gt;Model View Controller (MVC)&lt;/a&gt; applications with the ASP.NET framework as an alternative to ASP.NET webforms. &lt;/p&gt;  &lt;p&gt;In this session we'll take a look at the drivers behind MVC, the architecture of a typical ASP.NET MVC application, new features in ASP.NET that make it possible and we'll build a simple ASP.NET MVC application to explore the key concepts. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Speaker Bio&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Mike Ormond gained a BSc(Hons) in Information Engineering from the University of Strathclyde before moving south of the border many years ago. After spending some time with the Defence Research Agency, Mike joined Mars Electronics where he worked on automated payment systems. In 1996 he joined Mercury Interactive before heading over to Microsoft in 1997 to work in their developer support organisation. &lt;/p&gt;  &lt;p&gt;In 2003 he joined the Developer and Platform Group as a Developer Evangelist. Since then he’s travelled the length and breadth of the land talking about Microsoft’s platform and developer tools. Currently Mike’s interests include ASP.NET, AJAX, Silverlight and developing solutions with Office Open XML. &lt;/p&gt;  &lt;p&gt;When he’s not working, Mike likes to potter in his allotment and listen to Radio 4 on the wireless. &lt;/p&gt;  &lt;p&gt;You can contact Mike at: &lt;a href="http://mikeo.co.uk"&gt;http://mikeo.co.uk&lt;/a&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;[&lt;/strong&gt;&lt;strong&gt;&lt;a href="http://www.eventbrite.com/event/176356487/camblog" target="_blank"&gt;More details and registration&lt;/a&gt;&lt;/strong&gt;&lt;strong&gt;]&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:70d49101-c812-437e-804d-ed4fa902c486" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/asp.net" rel="tag"&gt;asp.net&lt;/a&gt;,&lt;a href="http://technorati.com/tags/asp.net%20mvc" rel="tag"&gt;asp.net mvc&lt;/a&gt;,&lt;a href="http://technorati.com/tags/.net" rel="tag"&gt;.net&lt;/a&gt;,&lt;a href="http://technorati.com/tags/microsoft" rel="tag"&gt;microsoft&lt;/a&gt;,&lt;a href="http://technorati.com/tags/mvc" rel="tag"&gt;mvc&lt;/a&gt;,&lt;a href="http://technorati.com/tags/edinburgh" rel="tag"&gt;edinburgh&lt;/a&gt;,&lt;a href="http://technorati.com/tags/scottish%20developers." rel="tag"&gt;scottish developers.&lt;/a&gt;&lt;/div&gt;&lt;img src="http://blog.colinmackay.net/aggbug/4076.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Colin Angus Mackay</dc:creator>
            <guid>http://blog.colinmackay.net/archive/2008/09/24/4076.aspx</guid>
            <pubDate>Wed, 24 Sep 2008 13:18:49 GMT</pubDate>
            <wfw:comment>http://blog.colinmackay.net/comments/4076.aspx</wfw:comment>
            <comments>http://blog.colinmackay.net/archive/2008/09/24/4076.aspx#feedback</comments>
            <wfw:commentRss>http://blog.colinmackay.net/comments/commentRss/4076.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>