<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" 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:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>VON#</title>
    <link>http://www.vonsharp.net/</link>
    <description>Confessions of a code junkie</description>
    <language>en-us</language>
    <copyright>Jon von Gillern</copyright>
    <lastBuildDate>Tue, 05 Aug 2008 19:33:09 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.0.7226.0</generator>
    <managingEditor>jvongillern@gmail.com</managingEditor>
    <webMaster>jvongillern@gmail.com</webMaster>
    <item>
      <trackback:ping>http://www.vonsharp.net/Trackback.aspx?guid=ae842809-9f83-4d9c-b547-9a6c3a2db694</trackback:ping>
      <pingback:server>http://www.vonsharp.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.vonsharp.net/PermaLink,guid,ae842809-9f83-4d9c-b547-9a6c3a2db694.aspx</pingback:target>
      <dc:creator>von</dc:creator>
      <wfw:comment>http://www.vonsharp.net/CommentView,guid,ae842809-9f83-4d9c-b547-9a6c3a2db694.aspx</wfw:comment>
      <wfw:commentRss>http://www.vonsharp.net/SyndicationService.asmx/GetEntryCommentsRss?guid=ae842809-9f83-4d9c-b547-9a6c3a2db694</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">Here is the question: <a href="http://www.dev102.com/2008/08/05/a-programming-job-interview-challenge-14-2d-geometry/">Programming
Job Interview Challenge Question Week #14</a><br /><br />
This week was a fun and interesting question. Here is the answer<br /><br />
Step 1. As you're adding points to the polygon, determine a bounding rectangle by
keeping track of the min x/y and the max x/y.<br /><br />
Step 2. Draw a line from the point you're interested in, to any point outside the
bounding rectangle (because you know the outside point can't be within the polygon).<br /><br />
Step 3. Count the number of intersections between your newly created line and the
polygon, if the number is even (0 included) the point in question is not within the
polygon, if the number of intersections is odd, then the point is within the polygon.<br /><br />
Examples:<br /><br />
Outside = Even Intersections<p></p><img src="http://www.vonsharp.net/content/binary/question14%20outside.jpg" border="0" /><br /><br />
Inside = Odd Intersections<br /><img src="http://www.vonsharp.net/content/binary/question14%20inside%20polygon.jpg" border="0" /></body>
      <title>Programming Job Interview Challenge Answer Week #14</title>
      <guid isPermaLink="false">http://www.vonsharp.net/PermaLink,guid,ae842809-9f83-4d9c-b547-9a6c3a2db694.aspx</guid>
      <link>http://www.vonsharp.net/ProgrammingJobInterviewChallengeAnswerWeek14.aspx</link>
      <pubDate>Tue, 05 Aug 2008 19:33:09 GMT</pubDate>
      <description>Here is the question: &lt;a href="http://www.dev102.com/2008/08/05/a-programming-job-interview-challenge-14-2d-geometry/"&gt;Programming
Job Interview Challenge Question Week #14&lt;/a&gt;
&lt;br&gt;
&lt;br&gt;
This week was a fun and interesting question. Here is the answer&lt;br&gt;
&lt;br&gt;
Step 1. As you're adding points to the polygon, determine a bounding rectangle by
keeping track of the min x/y and the max x/y.&lt;br&gt;
&lt;br&gt;
Step 2. Draw a line from the point you're interested in, to any point outside the
bounding rectangle (because you know the outside point can't be within the polygon).&lt;br&gt;
&lt;br&gt;
Step 3. Count the number of intersections between your newly created line and the
polygon, if the number is even (0 included) the point in question is not within the
polygon, if the number of intersections is odd, then the point is within the polygon.&lt;br&gt;
&lt;br&gt;
Examples:&lt;br&gt;
&lt;br&gt;
Outside = Even Intersections&lt;p&gt;
&lt;/p&gt;
&lt;img src="http://www.vonsharp.net/content/binary/question14%20outside.jpg" border="0"&gt;
&lt;br&gt;
&lt;br&gt;
Inside = Odd Intersections&lt;br&gt;
&lt;img src="http://www.vonsharp.net/content/binary/question14%20inside%20polygon.jpg" border="0"&gt;</description>
      <comments>http://www.vonsharp.net/CommentView,guid,ae842809-9f83-4d9c-b547-9a6c3a2db694.aspx</comments>
    </item>
    <item>
      <trackback:ping>http://www.vonsharp.net/Trackback.aspx?guid=0dc5e23a-c3ec-49c0-9a3a-2a4ec9ce83b1</trackback:ping>
      <pingback:server>http://www.vonsharp.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.vonsharp.net/PermaLink,guid,0dc5e23a-c3ec-49c0-9a3a-2a4ec9ce83b1.aspx</pingback:target>
      <dc:creator>von</dc:creator>
      <wfw:comment>http://www.vonsharp.net/CommentView,guid,0dc5e23a-c3ec-49c0-9a3a-2a4ec9ce83b1.aspx</wfw:comment>
      <wfw:commentRss>http://www.vonsharp.net/SyndicationService.asmx/GetEntryCommentsRss?guid=0dc5e23a-c3ec-49c0-9a3a-2a4ec9ce83b1</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <a href="http://www.dev102.com/2008/07/21/a-programming-job-interview-challenge-13-brackets/">Programming
Job Interview Challenge Question Week #13</a>
        <br />
        <br />
Highlight the text below for the answer.<br /><font color="#a9a9a9"><br /></font><font color="#ffffff">This is pretty simple, use a stack to track all open
brackets and on all closed pop the stack to see if you have the correct matching bracket.<br /><br /></font><font color="#ffffff" face="Courier New" size="2">private bool AreBracketsClosedProperly(string
input)<br />
{<br />
    Stack&lt;char&gt; openBrackets = new Stack&lt;char&gt;();<br />
    foreach (char bracket in input)<br />
    {<br />
        switch (bracket)<br />
        {<br />
            case '(':<br />
            case '[':<br />
            case '&lt;':<br />
            case '{':<br />
               
openBrackets.Push(bracket);<br />
               
break;<br /><br />
            case ')':<br />
               
if (openBrackets.Pop() != ')')<br />
                   
return false;<br />
            case ']':<br />
               
if (openBrackets.Pop() != ']')<br />
                   
return false;<br />
            case '&gt;':<br />
               
if (openBrackets.Pop() != '&gt;')<br />
                   
return false;<br />
            case '}':<br />
               
if (openBrackets.Pop() != '}')<br />
                   
return false;<br />
               
break;<br />
        }<br />
    }<br /><br />
    if (openBrackets.Count != 0)<br />
        return false;<br />
    else<br />
        return true;<br />
}</font><br /><p></p></body>
      <title>Programming Job Interview Challenge #13 Answer</title>
      <guid isPermaLink="false">http://www.vonsharp.net/PermaLink,guid,0dc5e23a-c3ec-49c0-9a3a-2a4ec9ce83b1.aspx</guid>
      <link>http://www.vonsharp.net/ProgrammingJobInterviewChallenge13Answer.aspx</link>
      <pubDate>Tue, 22 Jul 2008 13:00:08 GMT</pubDate>
      <description>&lt;a href="http://www.dev102.com/2008/07/21/a-programming-job-interview-challenge-13-brackets/"&gt;Programming
Job Interview Challenge Question Week #13&lt;/a&gt;
&lt;br&gt;
&lt;br&gt;
Highlight the text below for the answer.&lt;br&gt;
&lt;font color="#a9a9a9"&gt;
&lt;br&gt;
&lt;/font&gt;&lt;font color="#ffffff"&gt;This is pretty simple, use a stack to track all open
brackets and on all closed pop the stack to see if you have the correct matching bracket.&lt;br&gt;
&lt;br&gt;
&lt;/font&gt;&lt;font color="#ffffff" face="Courier New" size="2"&gt;private bool AreBracketsClosedProperly(string
input)&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Stack&amp;lt;char&amp;gt; openBrackets = new Stack&amp;lt;char&amp;gt;();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; foreach (char bracket in input)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; switch (bracket)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case '(':&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case '[':&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case '&amp;lt;':&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case '{':&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
openBrackets.Push(bracket);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
break;&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case ')':&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
if (openBrackets.Pop() != ')')&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
return false;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case ']':&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
if (openBrackets.Pop() != ']')&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
return false;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case '&amp;gt;':&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
if (openBrackets.Pop() != '&amp;gt;')&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
return false;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case '}':&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
if (openBrackets.Pop() != '}')&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
return false;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
break;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; if (openBrackets.Count != 0)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return false;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; else&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return true;&lt;br&gt;
}&lt;/font&gt;
&lt;br&gt;
&lt;p&gt;
&lt;/p&gt;</description>
      <comments>http://www.vonsharp.net/CommentView,guid,0dc5e23a-c3ec-49c0-9a3a-2a4ec9ce83b1.aspx</comments>
      <category>Stuff</category>
    </item>
    <item>
      <trackback:ping>http://www.vonsharp.net/Trackback.aspx?guid=5c5bb1a9-91c3-4c04-b73c-815c14a34e8a</trackback:ping>
      <pingback:server>http://www.vonsharp.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.vonsharp.net/PermaLink,guid,5c5bb1a9-91c3-4c04-b73c-815c14a34e8a.aspx</pingback:target>
      <dc:creator>von</dc:creator>
      <wfw:comment>http://www.vonsharp.net/CommentView,guid,5c5bb1a9-91c3-4c04-b73c-815c14a34e8a.aspx</wfw:comment>
      <wfw:commentRss>http://www.vonsharp.net/SyndicationService.asmx/GetEntryCommentsRss?guid=5c5bb1a9-91c3-4c04-b73c-815c14a34e8a</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">If you select the text below, you can find
the answer for this week's <a href="http://www.dev102.com/net/a-programming-job-interview-challenge-10-the-missing-number/">Job
Interview Challenge #10 from dev102.com</a>.<br /><br /><font color="#ffffff">This is a fairly easy problem, you can find the missing number
by taking the difference of the sum of the numbers you're given and what the total
should be for 1 to n. If you actually do the sum of 1 to n via a for loop, the time
complexity is O(2n), which is really just O(n), but if you want to get picky, you
can make it actually O(1n) by only looping through the list you're handed and instead
using the formula n(n+1)/2 to get the total of the numbers from 1 to n. 
<br /><br /></font><font color="#ffffff" face="Courier New" size="2">public static void FindMissingNumbers()<br />
{<br />
    //The O(n) that I discussed above is for 
<br />
    //the FindMissingNumber method only<br /><br />
    int n = 100;<br />
    List&lt;int&gt; numbers = CreateRandomList(n);<br />
    Console.WriteLine("Found:     Left Out Number
is: " + FindMissingNumber(numbers));<br /><br />
    n = 1000;<br />
    numbers = CreateRandomList(n);<br />
    Console.WriteLine("Found:     Left Out Number
is: " + FindMissingNumber(numbers));<br /><br />
    n = 10000;<br />
    numbers = CreateRandomList(n);<br />
    Console.WriteLine("Found:     Left Out Number
is: " + FindMissingNumber(numbers));<br /><br />
    //sample output<br />
    //Generated: Left Out Number is: 31<br />
    //Found:     Left Out Number is: 31<br />
    //Generated: Left Out Number is: 840<br />
    //Found:     Left Out Number is: 840<br />
    //Generated: Left Out Number is: 6289<br />
    //Found:     Left Out Number is: 6289<br /><br />
}<br /><br /><br /><br />
public static int FindMissingNumber(List&lt;int&gt; numbers)<br />
{<br />
    int numbersSum = numbers.Sum();<br />
    int n = numbers.Count;<br />
    int sum1ToNPlus1 = (n * (n + 1)) / 2; // this is much quicker than
actually summing 1 through n+1<br /><br />
    return sum1ToNPlus1 - numbersSum;<br />
}<br /><br />
public static List&lt;int&gt; CreateRandomList(int n)<br />
{<br />
    int nPlus1 = n + 1;<br />
    List&lt;int&gt; allNumbersList = new List&lt;int&gt;();<br />
    for (int i = 0; i &lt; nPlus1; i++)<br />
        allNumbersList.Add(i);<br /><br />
    Random rand = new Random();<br /><br />
    List&lt;int&gt; subsetNumbersList = new List&lt;int&gt;();<br />
    while (allNumbersList.Count &gt; 1)<br />
    {<br />
        int index = rand.Next(allNumbersList.Count);<br />
        subsetNumbersList.Add(allNumbersList[index]);<br />
        allNumbersList.RemoveAt(index);<br />
    }<br /><br />
    Console.WriteLine("Generated: Left Out Number is: " + allNumbersList[0]);<br /><br />
    return subsetNumbersList;<br />
}</font><p></p></body>
      <title>Programming Job Interview Challenge #10 Answer</title>
      <guid isPermaLink="false">http://www.vonsharp.net/PermaLink,guid,5c5bb1a9-91c3-4c04-b73c-815c14a34e8a.aspx</guid>
      <link>http://www.vonsharp.net/ProgrammingJobInterviewChallenge10Answer.aspx</link>
      <pubDate>Tue, 01 Jul 2008 16:00:57 GMT</pubDate>
      <description>If you select the text below, you can find the answer for this week's &lt;a href="http://www.dev102.com/net/a-programming-job-interview-challenge-10-the-missing-number/"&gt;Job
Interview Challenge #10 from dev102.com&lt;/a&gt;.&lt;br&gt;
&lt;br&gt;
&lt;font color="#ffffff"&gt;This is a fairly easy problem, you can find the missing number
by taking the difference of the sum of the numbers you're given and what the total
should be for 1 to n. If you actually do the sum of 1 to n via a for loop, the time
complexity is O(2n), which is really just O(n), but if you want to get picky, you
can make it actually O(1n) by only looping through the list you're handed and instead
using the formula n(n+1)/2 to get the total of the numbers from 1 to n. 
&lt;br&gt;
&lt;br&gt;
&lt;/font&gt;&lt;font color="#ffffff" face="Courier New" size="2"&gt;public static void FindMissingNumbers()&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; //The O(n) that I discussed above is for 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; //the FindMissingNumber method only&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; int n = 100;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; List&amp;lt;int&amp;gt; numbers = CreateRandomList(n);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Console.WriteLine("Found:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Left Out Number
is: " + FindMissingNumber(numbers));&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; n = 1000;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; numbers = CreateRandomList(n);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Console.WriteLine("Found:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Left Out Number
is: " + FindMissingNumber(numbers));&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; n = 10000;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; numbers = CreateRandomList(n);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Console.WriteLine("Found:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Left Out Number
is: " + FindMissingNumber(numbers));&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;//sample output&lt;br&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;//Generated: Left Out Number is: 31&lt;br&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;//Found:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Left Out Number is: 31&lt;br&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;//Generated: Left Out Number is: 840&lt;br&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;//Found:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Left Out Number is: 840&lt;br&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;//Generated: Left Out Number is: 6289&lt;br&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;//Found:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Left Out Number is: 6289&lt;br&gt;
&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
public static int FindMissingNumber(List&amp;lt;int&amp;gt; numbers)&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; int numbersSum = numbers.Sum();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; int n = numbers.Count;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; int sum1ToNPlus1 = (n * (n + 1)) / 2; // this is much quicker than
actually summing 1 through n+1&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; return sum1ToNPlus1 - numbersSum;&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
public static List&amp;lt;int&amp;gt; CreateRandomList(int n)&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; int nPlus1 = n + 1;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; List&amp;lt;int&amp;gt; allNumbersList = new List&amp;lt;int&amp;gt;();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; for (int i = 0; i &amp;lt; nPlus1; i++)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; allNumbersList.Add(i);&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Random rand = new Random();&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; List&amp;lt;int&amp;gt; subsetNumbersList = new List&amp;lt;int&amp;gt;();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; while (allNumbersList.Count &amp;gt; 1)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int index = rand.Next(allNumbersList.Count);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; subsetNumbersList.Add(allNumbersList[index]);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; allNumbersList.RemoveAt(index);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Console.WriteLine("Generated: Left Out Number is: " + allNumbersList[0]);&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; return subsetNumbersList;&lt;br&gt;
}&lt;/font&gt;
&lt;p&gt;
&lt;/p&gt;</description>
      <comments>http://www.vonsharp.net/CommentView,guid,5c5bb1a9-91c3-4c04-b73c-815c14a34e8a.aspx</comments>
    </item>
    <item>
      <trackback:ping>http://www.vonsharp.net/Trackback.aspx?guid=1b069045-33ad-494b-b76e-875340e0fb38</trackback:ping>
      <pingback:server>http://www.vonsharp.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.vonsharp.net/PermaLink,guid,1b069045-33ad-494b-b76e-875340e0fb38.aspx</pingback:target>
      <dc:creator>von</dc:creator>
      <wfw:comment>http://www.vonsharp.net/CommentView,guid,1b069045-33ad-494b-b76e-875340e0fb38.aspx</wfw:comment>
      <wfw:commentRss>http://www.vonsharp.net/SyndicationService.asmx/GetEntryCommentsRss?guid=1b069045-33ad-494b-b76e-875340e0fb38</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">I've been trying to keep up with the Job
Interview line of posts over at dev102.com, but unfortunately I've been running out
of time to do all of them. Anyway, this weeks question can be found <a href="http://www.dev102.com/net/a-programming-job-interview-challenge-8-a-needle-in-a-haystack/">here</a>.
Stop reading if you don't want the answer.<br /><br />
This problem can be solved using a Finite State Machine. The only thing you're going
to store is the current state of the machine, once you reach the end of the machine,
you'll alert. On initialization of the piping component, you'll build a finite state
machine for the given alert sequence. Every time you are given a message you check
what you should do with the state machine based on where you are currently at.<br /><br />
I was going to write out the code to do this, but it becomes a little tricky when
you have repeating data in your alert sequence because if you get a message you're
not expecting you don't necessarily want to reset the state machine to its initial
state. For example, if the alert sequence was "A, A, A, A, B", and your input is "A,
A, A, A, A, B", you don't want to reset the machine to the first state when you get
that 5th A, you want it to stay in its current state.<br /><br /><br /><img src="http://www.vonsharp.net/content/binary/Statemachine12.jpg" border="0" /></body>
      <title>Programming Job Interview Challenge #8 Answer</title>
      <guid isPermaLink="false">http://www.vonsharp.net/PermaLink,guid,1b069045-33ad-494b-b76e-875340e0fb38.aspx</guid>
      <link>http://www.vonsharp.net/ProgrammingJobInterviewChallenge8Answer.aspx</link>
      <pubDate>Mon, 16 Jun 2008 17:48:03 GMT</pubDate>
      <description>I've been trying to keep up with the Job Interview line of posts over at dev102.com, but unfortunately I've been running out of time to do all of them. Anyway, this weeks question can be found &lt;a href="http://www.dev102.com/net/a-programming-job-interview-challenge-8-a-needle-in-a-haystack/"&gt;here&lt;/a&gt;.
Stop reading if you don't want the answer.&lt;br&gt;
&lt;br&gt;
This problem can be solved using a Finite State Machine. The only thing you're going
to store is the current state of the machine, once you reach the end of the machine,
you'll alert. On initialization of the piping component, you'll build a finite state
machine for the given alert sequence. Every time you are given a message you check
what you should do with the state machine based on where you are currently at.&lt;br&gt;
&lt;br&gt;
I was going to write out the code to do this, but it becomes a little tricky when
you have repeating data in your alert sequence because if you get a message you're
not expecting you don't necessarily want to reset the state machine to its initial
state. For example, if the alert sequence was "A, A, A, A, B", and your input is "A,
A, A, A, A, B", you don't want to reset the machine to the first state when you get
that 5th A, you want it to stay in its current state.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;img src="http://www.vonsharp.net/content/binary/Statemachine12.jpg" border="0"&gt;</description>
      <comments>http://www.vonsharp.net/CommentView,guid,1b069045-33ad-494b-b76e-875340e0fb38.aspx</comments>
      <category>Stuff</category>
    </item>
    <item>
      <trackback:ping>http://www.vonsharp.net/Trackback.aspx?guid=8631367a-6e86-4e54-a217-5c4162b2dd22</trackback:ping>
      <pingback:server>http://www.vonsharp.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.vonsharp.net/PermaLink,guid,8631367a-6e86-4e54-a217-5c4162b2dd22.aspx</pingback:target>
      <dc:creator>von</dc:creator>
      <wfw:comment>http://www.vonsharp.net/CommentView,guid,8631367a-6e86-4e54-a217-5c4162b2dd22.aspx</wfw:comment>
      <wfw:commentRss>http://www.vonsharp.net/SyndicationService.asmx/GetEntryCommentsRss?guid=8631367a-6e86-4e54-a217-5c4162b2dd22</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">Do yourself a favor, next time you have
a build error that says something like: The type or namespace name 'XYZ' could not
be found (are you missing a using directive or an assembly reference?). Double click
the error (which will highlight the unknown type) then hit Alt+Shift+F10. This will
bring up a dropdown that has all of the types that match that class name and hitting
enter will automatically add the appropriate using statement. Thank you Visual Studio!<br /><br /><br /><p></p></body>
      <title>Quick Fix - Missing Using Statements</title>
      <guid isPermaLink="false">http://www.vonsharp.net/PermaLink,guid,8631367a-6e86-4e54-a217-5c4162b2dd22.aspx</guid>
      <link>http://www.vonsharp.net/QuickFixMissingUsingStatements.aspx</link>
      <pubDate>Thu, 05 Jun 2008 18:03:01 GMT</pubDate>
      <description>Do yourself a favor, next time you have a build error that says
something like: The type or namespace name 'XYZ' could not be found
(are you missing a using directive or an assembly reference?). Double
click the error (which will highlight the unknown type) then hit
Alt+Shift+F10. This will bring up a dropdown that has all of the types
that match that class name and hitting enter will automatically add the
appropriate using statement. Thank you Visual Studio!&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;p&gt;
&lt;/p&gt;</description>
      <comments>http://www.vonsharp.net/CommentView,guid,8631367a-6e86-4e54-a217-5c4162b2dd22.aspx</comments>
      <category>Tips and Tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.vonsharp.net/Trackback.aspx?guid=b432eb70-b3d2-4b60-9879-28e51533336a</trackback:ping>
      <pingback:server>http://www.vonsharp.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.vonsharp.net/PermaLink,guid,b432eb70-b3d2-4b60-9879-28e51533336a.aspx</pingback:target>
      <dc:creator>von</dc:creator>
      <wfw:comment>http://www.vonsharp.net/CommentView,guid,b432eb70-b3d2-4b60-9879-28e51533336a.aspx</wfw:comment>
      <wfw:commentRss>http://www.vonsharp.net/SyndicationService.asmx/GetEntryCommentsRss?guid=b432eb70-b3d2-4b60-9879-28e51533336a</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">So one of the guys over at <a href="http://www.dev102.com">dev102.com</a> has
been posting job interview questions. While the most recent isn't the best interview
question in the world, I thought I'd share the answer if anyone is interested.<br /><br />
Here is the <a href="http://www.dev102.com/2008/05/19/a-programming-job-interview-challenge-4/">question</a>: <blockquote cite="Dev102" style="background-color: LightGray;"> How
would you implement the following method: Foo(7) = 17 and Foo(17) = 7. Any other input
to that method is not defined so you can return anything you want. Just follow those
rules: 
<ul><li>
Conditional statements (if, switch, …) are not allowed.</li><li>
Usage of containers (hash tables, arrays, …) are not allowed.</li></ul></blockquote><br />
The answer is crazy simple. Highlight the text below to reveal the answer.<br /><br /><font color="#ffffff">public int Foo(int x)<br />
{<br />
    return -1 * x + 24;<br />
}<br /><br />
My Algebra teacher would be so proud.</font><br /></body>
      <title>Programming Job Interview Challenge #4 Answer</title>
      <guid isPermaLink="false">http://www.vonsharp.net/PermaLink,guid,b432eb70-b3d2-4b60-9879-28e51533336a.aspx</guid>
      <link>http://www.vonsharp.net/ProgrammingJobInterviewChallenge4Answer.aspx</link>
      <pubDate>Mon, 19 May 2008 17:48:47 GMT</pubDate>
      <description>So one of the guys over at &lt;a href="http://www.dev102.com"&gt;dev102.com&lt;/a&gt; has been
posting job interview questions. While the most recent isn't the best interview question
in the world, I thought I'd share the answer if anyone is interested.&lt;br&gt;
&lt;br&gt;
Here is the &lt;a href="http://www.dev102.com/2008/05/19/a-programming-job-interview-challenge-4/"&gt;question&lt;/a&gt;: &lt;blockquote cite="Dev102" style="background-color: LightGray;"&gt; How
would you implement the following method: Foo(7) = 17 and Foo(17) = 7. Any other input
to that method is not defined so you can return anything you want. Just follow those
rules: 
&lt;ul&gt;
&lt;li&gt;
Conditional statements (if, switch, …) are not allowed.&lt;/li&gt;
&lt;li&gt;
Usage of containers (hash tables, arrays, …) are not allowed.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt; 
&lt;br&gt;
The answer is crazy simple. Highlight the text below to reveal the answer.&lt;br&gt;
&lt;br&gt;
&lt;font color="#ffffff"&gt;public int Foo(int x)&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; return -1 * x + 24;&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
My Algebra teacher would be so proud.&lt;/font&gt;
&lt;br&gt;</description>
      <comments>http://www.vonsharp.net/CommentView,guid,b432eb70-b3d2-4b60-9879-28e51533336a.aspx</comments>
      <category>Stuff</category>
    </item>
    <item>
      <trackback:ping>http://www.vonsharp.net/Trackback.aspx?guid=b9340607-4494-47ae-b90c-85382bd1f571</trackback:ping>
      <pingback:server>http://www.vonsharp.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.vonsharp.net/PermaLink,guid,b9340607-4494-47ae-b90c-85382bd1f571.aspx</pingback:target>
      <dc:creator>von</dc:creator>
      <wfw:comment>http://www.vonsharp.net/CommentView,guid,b9340607-4494-47ae-b90c-85382bd1f571.aspx</wfw:comment>
      <wfw:commentRss>http://www.vonsharp.net/SyndicationService.asmx/GetEntryCommentsRss?guid=b9340607-4494-47ae-b90c-85382bd1f571</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">So you may or may not have noticed that
I haven't posted anything for the past two months and that most of my links have been
broken. Well, the reason being is that I run a small intranet application for a group
I belonged to at Iowa State. When I moved the application over to <a href="http://www.discountasp.net">discountasp.net</a> the
application was living in a subdirectory of my vonsharp.net domain, and in doing so
I ran into all sorts of messy web.config problems.<br /><br />
Well, I think finally have solved all the issues and should be posting once or twice
a week from here on out. But just incase you're interested here is how I resolved
my issues.<br /><br />
In order to run a seperate web application in a subdirectory of your DasBlog directory
you'll need to do the following:<br /><br />
1. In your DasBlog web.config, wrap all of the configuration tag's children in one
single "location" tag, except for the configSections tag and the runtime tag. Your
dasBlog web.config should look something like:<br /><br /><pre><span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;">&lt;configuration&gt;
&lt;configSections&gt; ... &lt;/configSections&gt; &lt;runtime&gt; ... &lt;runtime&gt;
&lt;location path=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">""</span> allowOverride=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"true"</span>&gt;
&lt;newtelligence.ControlImages ... &gt; ... &lt;system.web ... &gt; ... &lt;/location&gt;
&lt;configuration&gt;</span></pre>
Note: DO NOT CHANGE THE PATH, LEAVE IT AS AN EMPTY STRING<br /><br />
2. Then in your new sub-directory web application's web.config you'll need to do the
same thing, and leave the path string empty as long as your web.config is actually
sitting in the sub directory. As I understand it, its possible to define this in your
dasBlog's web config but I'd recommend against it. 
<br /><br />
Here is the tricky part. The location tag for the sub-directory application acts just
like object inheritence. So your web application's web.config will inherit all of
the same configuration from its parent directory. Since you probably don't want dasBlog
running in your sub directory, you need to clear out it's http modules. So in your
new web app's web config add the following markup to the httpModules section<br /><br /><pre><span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;">&lt;httpModules&gt;
&lt;!-- gets rid of dasBlog Modules --&gt; &lt;remove name=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"UrlMapperModule"</span>/&gt;
&lt;remove name=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"TitleMapperModule"</span>/&gt;
&lt;remove name=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"ProfileMapperModule"</span>/&gt;
&lt;remove name=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"ControlImageModule"</span>/&gt;
&lt;remove name=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"CompressionModule"</span>/&gt;
&lt;remove name=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"IPBlackList"</span>/&gt;
&lt;/httpModules&gt;</span></pre>
Hope this helps anyone who is going through the same pain that I had.<br /><br /><p></p></body>
      <title>DasBlog and the Web.Config Location Tag</title>
      <guid isPermaLink="false">http://www.vonsharp.net/PermaLink,guid,b9340607-4494-47ae-b90c-85382bd1f571.aspx</guid>
      <link>http://www.vonsharp.net/DasBlogAndTheWebConfigLocationTag.aspx</link>
      <pubDate>Sun, 18 May 2008 16:02:55 GMT</pubDate>
      <description>So you may or may not have noticed that I haven't posted anything for the past two months and that most of my links have been broken. Well, the reason being is that I run a small intranet application for a group I belonged to at Iowa State. When I moved the application over to &lt;a href="http://www.discountasp.net"&gt;discountasp.net&lt;/a&gt; the
application was living in a subdirectory of my vonsharp.net domain, and in doing so
I ran into all sorts of messy web.config problems.&lt;br&gt;
&lt;br&gt;
Well, I think finally have solved all the issues and should be posting once or twice
a week from here on out. But just incase you're interested here is how I resolved
my issues.&lt;br&gt;
&lt;br&gt;
In order to run a seperate web application in a subdirectory of your DasBlog directory
you'll need to do the following:&lt;br&gt;
&lt;br&gt;
1. In your DasBlog web.config, wrap all of the configuration tag's children in one
single "location" tag, except for the configSections tag and the runtime tag. Your
dasBlog web.config should look something like:&lt;br&gt;
&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;&amp;lt;configuration&amp;gt;
&amp;lt;configSections&amp;gt; ... &amp;lt;/configSections&amp;gt; &amp;lt;runtime&amp;gt; ... &amp;lt;runtime&amp;gt;
&amp;lt;location path=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;""&lt;/span&gt; allowOverride=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"true"&lt;/span&gt;&amp;gt;
&amp;lt;newtelligence.ControlImages ... &amp;gt; ... &amp;lt;system.web ... &amp;gt; ... &amp;lt;/location&amp;gt;
&amp;lt;configuration&amp;gt;&lt;/span&gt;&lt;/pre&gt;
Note: DO NOT CHANGE THE PATH, LEAVE IT AS AN EMPTY STRING&lt;br&gt;
&lt;br&gt;
2. Then in your new sub-directory web application's web.config you'll need to do the
same thing, and leave the path string empty as long as your web.config is actually
sitting in the sub directory. As I understand it, its possible to define this in your
dasBlog's web config but I'd recommend against it. 
&lt;br&gt;
&lt;br&gt;
Here is the tricky part. The location tag for the sub-directory application acts just
like object inheritence. So your web application's web.config will inherit all of
the same configuration from its parent directory. Since you probably don't want dasBlog
running in your sub directory, you need to clear out it's http modules. So in your
new web app's web config add the following markup to the httpModules section&lt;br&gt;
&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;&amp;lt;httpModules&amp;gt;
&amp;lt;!-- gets rid of dasBlog Modules --&amp;gt; &amp;lt;remove name=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"UrlMapperModule"&lt;/span&gt;/&amp;gt;
&amp;lt;remove name=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"TitleMapperModule"&lt;/span&gt;/&amp;gt;
&amp;lt;remove name=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"ProfileMapperModule"&lt;/span&gt;/&amp;gt;
&amp;lt;remove name=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"ControlImageModule"&lt;/span&gt;/&amp;gt;
&amp;lt;remove name=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"CompressionModule"&lt;/span&gt;/&amp;gt;
&amp;lt;remove name=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"IPBlackList"&lt;/span&gt;/&amp;gt;
&amp;lt;/httpModules&amp;gt;&lt;/span&gt;&lt;/pre&gt;
Hope this helps anyone who is going through the same pain that I had.&lt;br&gt;
&lt;br&gt;
&lt;p&gt;
&lt;/p&gt;</description>
      <comments>http://www.vonsharp.net/CommentView,guid,b9340607-4494-47ae-b90c-85382bd1f571.aspx</comments>
      <category>Tips and Tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.vonsharp.net/Trackback.aspx?guid=c388f588-48ac-4c17-9b85-8c95b7144ad8</trackback:ping>
      <pingback:server>http://www.vonsharp.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.vonsharp.net/PermaLink,guid,c388f588-48ac-4c17-9b85-8c95b7144ad8.aspx</pingback:target>
      <dc:creator>von</dc:creator>
      <wfw:comment>http://www.vonsharp.net/CommentView,guid,c388f588-48ac-4c17-9b85-8c95b7144ad8.aspx</wfw:comment>
      <wfw:commentRss>http://www.vonsharp.net/SyndicationService.asmx/GetEntryCommentsRss?guid=c388f588-48ac-4c17-9b85-8c95b7144ad8</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">I have a big problem with launching firefox
everytime I have 20 seconds of downtime (like when I'm building a big solution, or
I'm waiting for a large file to load in my application). By the time I look at whatever
site I decide to go to, it sucks up more than the 20 seconds of downtime and costs
me a lot of time "context switching". 
<br /><br />
Something that has helped me with this problem: I took firefox off of my quick launch
bar and put it on the desktop. I now have to be much more deliberate in when I actually
need to use the "tubes".<br /><br /><p></p><img src="http://www.vonsharp.net/content/binary/removeQuickLaunch.jpg" border="0" /><br /><br /></body>
      <title>Boost Your Productivity - Remove Firefox Quick Launch</title>
      <guid isPermaLink="false">http://www.vonsharp.net/PermaLink,guid,c388f588-48ac-4c17-9b85-8c95b7144ad8.aspx</guid>
      <link>http://www.vonsharp.net/BoostYourProductivityRemoveFirefoxQuickLaunch.aspx</link>
      <pubDate>Tue, 18 Mar 2008 14:01:17 GMT</pubDate>
      <description>I have a big problem with launching firefox everytime I have 20 seconds of downtime (like when I'm building a big solution, or I'm waiting for a large file to load in my application). By the time I look at whatever site I decide to go to, it sucks up more than the 20 seconds of downtime and costs me a lot of time "context switching". &lt;br&gt;
&lt;br&gt;
Something that has helped me with this problem: I took firefox off of my quick launch
bar and put it on the desktop. I now have to be much more deliberate in when I actually
need to use the "tubes".&lt;br&gt;
&lt;br&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img src="http://www.vonsharp.net/content/binary/removeQuickLaunch.jpg" border="0"&gt;
&lt;br&gt;
&lt;br&gt;</description>
      <comments>http://www.vonsharp.net/CommentView,guid,c388f588-48ac-4c17-9b85-8c95b7144ad8.aspx</comments>
      <category>Tips and Tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.vonsharp.net/Trackback.aspx?guid=8dba1d96-07ed-496a-bf0d-1fe181376114</trackback:ping>
      <pingback:server>http://www.vonsharp.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.vonsharp.net/PermaLink,guid,8dba1d96-07ed-496a-bf0d-1fe181376114.aspx</pingback:target>
      <dc:creator>von</dc:creator>
      <wfw:comment>http://www.vonsharp.net/CommentView,guid,8dba1d96-07ed-496a-bf0d-1fe181376114.aspx</wfw:comment>
      <wfw:commentRss>http://www.vonsharp.net/SyndicationService.asmx/GetEntryCommentsRss?guid=8dba1d96-07ed-496a-bf0d-1fe181376114</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">I just read this excellent essay by Jeff
Moser on his blog and thought I'd share it with all of you. I highly recommend it,
especially for students who are interested in a career in software development.<br /><br /><a href="http://www.moserware.com/2008/03/what-does-it-take-to-become-grandmaster.html">What
does it take to become a Software Grandmaster<br /></a><p></p></body>
      <title>Software Grandmaster</title>
      <guid isPermaLink="false">http://www.vonsharp.net/PermaLink,guid,8dba1d96-07ed-496a-bf0d-1fe181376114.aspx</guid>
      <link>http://www.vonsharp.net/SoftwareGrandmaster.aspx</link>
      <pubDate>Mon, 03 Mar 2008 18:15:26 GMT</pubDate>
      <description>I just read this excellent essay by Jeff Moser on his blog and thought I'd share it with all of you. I highly recommend it, especially for students who are interested in a career in software development.&lt;br&gt;
&lt;br&gt;
&lt;a href="http://www.moserware.com/2008/03/what-does-it-take-to-become-grandmaster.html"&gt;What
does it take to become a Software Grandmaster&lt;br&gt;
&lt;/a&gt;
&lt;p&gt;
&lt;/p&gt;</description>
      <comments>http://www.vonsharp.net/CommentView,guid,8dba1d96-07ed-496a-bf0d-1fe181376114.aspx</comments>
    </item>
    <item>
      <trackback:ping>http://www.vonsharp.net/Trackback.aspx?guid=536dbbb8-ccd9-4251-9685-1dc83a95ef27</trackback:ping>
      <pingback:server>http://www.vonsharp.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.vonsharp.net/PermaLink,guid,536dbbb8-ccd9-4251-9685-1dc83a95ef27.aspx</pingback:target>
      <dc:creator>von</dc:creator>
      <wfw:comment>http://www.vonsharp.net/CommentView,guid,536dbbb8-ccd9-4251-9685-1dc83a95ef27.aspx</wfw:comment>
      <wfw:commentRss>http://www.vonsharp.net/SyndicationService.asmx/GetEntryCommentsRss?guid=536dbbb8-ccd9-4251-9685-1dc83a95ef27</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">I saw a <a href="http://ohnull.com/blog/2008/02/27/immediate-window-a-forgotten-tool/">post</a> on <a href="http://ohnull.com/blog/2008/02/27/immediate-window-a-forgotten-tool/">oh
null!</a> that talks about how you can evaluate expressions within the immediate window,
whether you're simply retrieving a variable or performing a calculation on multiple
variables. I personally like to do all of this in the Watch Window because I can have
an easy history of what variables I've interrogated. Like the immediate window, you
can call Methods and display the results, but since methods can change state, they
will not execute automatically after you step into a new line of code, but there is
a nice little refresh button that will re-execute your method call. 
<br /><br /><img src="http://www.vonsharp.net/content/binary/watchWindow.jpg" border="0" /><br /><br />
As I understand it, the watch window is a wrapper around the simpler functionality
of the immediate window, so it also supports Intellisense. But there are some things
that you can only do in the immediate window, like the .load [dll] command which lets
you import another assembly for your use, which is pretty damn slick. I've only ever
really used that feature in one scenario: to load the Son of Strike assembly which
helps you get detailed information on your executable (very detailed call stack info,
very granular heap information, but kind of hard to use). 
<br /><br />
Another cool thing you can do in your immediate window: Declare new variables. Those
variables will have the same scope as the current breakpoint in execution, but the
ability opens the doors to some neat possibilities. For instance, you could declare
a new variable, copy a subset of information from your current in scope variables
and then use my <a href="http://www.vonsharp.net/PutDownTheXmlNodeAndStepAwayFromTheStringBuilder.aspx">Xml
Utility Methods</a> to copy your new object out to disk! I'm not quite sure why you
would need to do that, but its nice to be able to!<br /></body>
      <title>Most Everything the Immediate Window Can Do the Watch Window Can Do Better</title>
      <guid isPermaLink="false">http://www.vonsharp.net/PermaLink,guid,536dbbb8-ccd9-4251-9685-1dc83a95ef27.aspx</guid>
      <link>http://www.vonsharp.net/MostEverythingTheImmediateWindowCanDoTheWatchWindowCanDoBetter.aspx</link>
      <pubDate>Fri, 29 Feb 2008 14:53:29 GMT</pubDate>
      <description>I
saw a &lt;a href="http://ohnull.com/blog/2008/02/27/immediate-window-a-forgotten-tool/"&gt;post&lt;/a&gt; on &lt;a href="http://ohnull.com/blog/2008/02/27/immediate-window-a-forgotten-tool/"&gt;oh
null!&lt;/a&gt; that talks about how you can evaluate expressions within the immediate window,
whether you're simply retrieving a variable or performing a calculation on multiple
variables. I personally like to do all of this in the Watch Window because I can have
an easy history of what variables I've interrogated. Like the immediate window, you
can call Methods and display the results, but since methods can change state, they
will not execute automatically after you step into a new line of code, but there is
a nice little refresh button that will re-execute your method call. 
&lt;br&gt;
&lt;br&gt;
&lt;img src="http://www.vonsharp.net/content/binary/watchWindow.jpg" border="0"&gt;
&lt;br&gt;
&lt;br&gt;
As I understand it, the watch window is a wrapper around the simpler functionality
of the immediate window, so it also supports Intellisense. But there are some things
that you can only do in the immediate window, like the .load [dll] command which lets
you import another assembly for your use, which is pretty damn slick. I've only ever
really used that feature in one scenario: to load the Son of Strike assembly which
helps you get detailed information on your executable (very detailed call stack info,
very granular heap information, but kind of hard to use). 
&lt;br&gt;
&lt;br&gt;
Another cool thing you can do in your immediate window: Declare new variables. Those
variables will have the same scope as the current breakpoint in execution, but the
ability opens the doors to some neat possibilities. For instance, you could declare
a new variable, copy a subset of information from your current in scope variables
and then use my &lt;a href="http://www.vonsharp.net/PutDownTheXmlNodeAndStepAwayFromTheStringBuilder.aspx"&gt;Xml
Utility Methods&lt;/a&gt; to copy your new object out to disk! I'm not quite sure why you
would need to do that, but its nice to be able to!&lt;br&gt;

    
    


</description>
      <comments>http://www.vonsharp.net/CommentView,guid,536dbbb8-ccd9-4251-9685-1dc83a95ef27.aspx</comments>
      <category>Tips and Tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.vonsharp.net/Trackback.aspx?guid=c8ff4f30-3dbd-427a-88ea-7252e5219a22</trackback:ping>
      <pingback:server>http://www.vonsharp.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.vonsharp.net/PermaLink,guid,c8ff4f30-3dbd-427a-88ea-7252e5219a22.aspx</pingback:target>
      <dc:creator>von</dc:creator>
      <wfw:comment>http://www.vonsharp.net/CommentView,guid,c8ff4f30-3dbd-427a-88ea-7252e5219a22.aspx</wfw:comment>
      <wfw:commentRss>http://www.vonsharp.net/SyndicationService.asmx/GetEntryCommentsRss?guid=c8ff4f30-3dbd-427a-88ea-7252e5219a22</wfw:commentRss>
      <slash:comments>3</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">With my work, I regularly deal with obscene
amounts. Of course, our users demand that this information loads instantly and without
running out of memory. So optimizing our data storage objects for time and memory
constraints is incredibly important. So far, I think I've done a pretty good job,
because I can load 125 million data points in a shade over 3 seconds (using a database
to store some of this data flew out the window a while ago). But getting to this point
has been an interesting journey. Doing quick prototyping of prospective storage mechanisms
has been incredibly important and I thought I'd share some of the utility methods/classes
I've created to speed up the process.<br /><br />
The first piece of code is incredibly similar to my <a href="http://www.vonsharp.net/StopwatchWriterClass.aspx">StopwatchWriter</a> Class.
Instead of starting and stopping a Stopwatch, we're asking the garbage collector how
much total memory is being used (in bytes), before and after you instantiate an object
(or a whole set of objects)<br /><pre><span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">public</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">class</span> MemoryWriter
: IDisposable { <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">long</span> _startMem; <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">string</span> _text; <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">public</span> MemoryWriter(<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">string</span> text)
{ _text <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> text <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">+</span><span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"
- "</span>; _startMem <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> GC.GetTotalMemory(<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">true</span>);
} <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">public</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">void</span> Dispose()
{ Console.WriteLine(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"mem:
"</span><span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">+</span> _text <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">+</span> (GC.GetTotalMemory(<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">true</span>) <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">-</span><br />
_startMem).ToString()); } } Usage looks like: <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">using</span> (<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">new</span> MemoryWriter(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"CrazyBigObject"</span>))
{ CrazyBigObject myCrazyBigObject <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> LoadCrazyBigObject(42);
}</span></pre><br />
This is the most accurate way of figuring out how much memory a specific object is
taking up in memory. But there is a limitation to this method if you're using it in
a multi-threaded application, such as a Win Form because another running thread could
dereference objects on the heap after you've instantiated your MemoryWriter , but
before its been disposed. I prefer to only use this class in small throw away console
applications, to make my results as accurate as possible. 
<br /><br />
Sometimes though, you'll find yourself looking at an object in someone else's code
and you want to easily find out how much memory its taking up, but the object in question
is "built" over several methods along with several other objects that you don't care
about. Which makes it impossible to use theMemoryWriter Class. You can use a memory
profiling application to do this, but I've found that they are notoriously hard to
pick up and use. And due to the nature of how they work, they take ages to work because
they have to take a snapshot before and after the code you care about (i.e. copy your
700MB object heap twice and then "diff" the two heaps). So I've wrote two small methods
that serialize the object to a stream and then return the length of the stream. Note:
This is approximately how much data the object is holding in memory. It may besignificantly
less than how much space it takes up on the heap. Case in point: Dictionary&lt;K,
V&gt; takes up much more space in memory than it does when serialized.That's because
it only serialized the key value pairs and it re-hydrates the dictionary on deserialization.
Nor will it reflect the size of any properties on your object that are marked with
the NonSerialized attribute. So it is far from perfect, but it helps give you an idea
with out the pain of using a memory profiler . You can use these methods by setting
a break point and calling them in your watch window (I prefer doing that over the
immediate window).<br /><br /><pre><span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"><span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;">///
&lt;summary&gt;</span><span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;">///
Returns a rough approximation of the size of an object 
<br />
/// (including ALL objects in/directly referenced by the object)</span><span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;">///
&lt;/summary&gt;</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">public</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">static</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">long</span> ApproxSize(<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">object</span> obj)
{ BinaryFormatter formatter <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">new</span> BinaryFormatter(); <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">long</span> length; <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">using</span> (MemoryStream
stream <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">new</span> MemoryStream())
{ formatter.Serialize(stream, obj); stream.Seek(0, SeekOrigin.Begin); length <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> stream.Length;
} <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">return</span> length;
} </span></pre><br />
Sometimes though, your object is very large and serializing the object in memory will
cause an OutOfMemory Exception. So use the below method instead, it serializes the
object to disk and gives you the size of the file (and deletes the file after its
done). 
<br /><br /><pre><span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"><span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;">///
&lt;summary&gt;<br />
/// Returns the approximate size of very large objects 
<br />
/// (time intensive) in bytes.<br />
/// &lt;/summary&gt;</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">public</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">static</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">long</span> ApproxSizeLarge(<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">object</span> obj)
{ FileInfo info <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">new</span> FileInfo(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">@"c:\approxSizeTemp"</span>);
BinaryFormatter formatter <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">new</span> BinaryFormatter(); <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">using</span> (StreamWriter
writer <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">new</span> StreamWriter(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">@"c:\approxSizeTemp"</span>))
{ formatter.Serialize(writer.BaseStream, obj); } <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">long</span> length <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> info.Length;
info.Delete(); <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">return</span> length;
}</span></pre><br /><p></p></body>
      <title>Quick and Dirty Memory Utility Methods</title>
      <guid isPermaLink="false">http://www.vonsharp.net/PermaLink,guid,c8ff4f30-3dbd-427a-88ea-7252e5219a22.aspx</guid>
      <link>http://www.vonsharp.net/QuickAndDirtyMemoryUtilityMethods.aspx</link>
      <pubDate>Wed, 27 Feb 2008 19:36:28 GMT</pubDate>
      <description>With my work, I regularly
deal with obscene amounts. Of course, our users demand that this
information loads instantly and without running out of memory. So
optimizing our data storage objects for time and memory constraints is
incredibly important. So far, I think I've done a pretty good job,
because I can load 125 million data points in a shade over 3 seconds
(using a database to store some of this data flew out the window a
while ago). But getting to this point has been an interesting journey.
Doing quick prototyping of prospective storage mechanisms has been
incredibly important and I thought I'd share some of the utility
methods/classes I've created to speed up the process.&lt;br&gt;
&lt;br&gt;
The first piece of code is incredibly similar to my &lt;a href="http://www.vonsharp.net/StopwatchWriterClass.aspx"&gt;StopwatchWriter&lt;/a&gt; Class.
Instead of starting and stopping a Stopwatch, we're asking the garbage collector how
much total memory is being used (in bytes), before and after you instantiate an object
(or a whole set of objects)&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;class&lt;/span&gt; MemoryWriter
: IDisposable { &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;long&lt;/span&gt; _startMem; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;string&lt;/span&gt; _text; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt; MemoryWriter(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;string&lt;/span&gt; text)
{ _text &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; text &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;+&lt;/span&gt; &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"
- "&lt;/span&gt;; _startMem &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; GC.GetTotalMemory(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;true&lt;/span&gt;);
} &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;void&lt;/span&gt; Dispose()
{ Console.WriteLine(&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"mem:
"&lt;/span&gt; &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;+&lt;/span&gt; _text &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;+&lt;/span&gt; (GC.GetTotalMemory(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;true&lt;/span&gt;) &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;-&lt;/span&gt; 
&lt;br&gt;
_startMem).ToString()); } } Usage looks like: &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;using&lt;/span&gt; (&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;new&lt;/span&gt; MemoryWriter(&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"CrazyBigObject"&lt;/span&gt;))
{ CrazyBigObject myCrazyBigObject &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; LoadCrazyBigObject(42);
}&lt;/span&gt;&lt;/pre&gt;
&lt;br&gt;
This is the most accurate way of figuring out how much memory a specific object is
taking up in memory. But there is a limitation to this method if you're using it in
a multi-threaded application, such as a Win Form because another running thread could
dereference objects on the heap after you've instantiated your MemoryWriter , but
before its been disposed. I prefer to only use this class in small throw away console
applications, to make my results as accurate as possible. 
&lt;br&gt;
&lt;br&gt;
Sometimes though, you'll find yourself looking at an object in someone else's code
and you want to easily find out how much memory its taking up, but the object in question
is "built" over several methods along with several other objects that you don't care
about. Which makes it impossible to use theMemoryWriter Class. You can use a memory
profiling application to do this, but I've found that they are notoriously hard to
pick up and use. And due to the nature of how they work, they take ages to work because
they have to take a snapshot before and after the code you care about (i.e. copy your
700MB object heap twice and then "diff" the two heaps). So I've wrote two small methods
that serialize the object to a stream and then return the length of the stream. Note:
This is approximately how much data the object is holding in memory. It may besignificantly
less than how much space it takes up on the heap. Case in point: Dictionary&amp;lt;K,
V&amp;gt; takes up much more space in memory than it does when serialized.That's because
it only serialized the key value pairs and it re-hydrates the dictionary on deserialization.
Nor will it reflect the size of any properties on your object that are marked with
the NonSerialized attribute. So it is far from perfect, but it helps give you an idea
with out the pain of using a memory profiler . You can use these methods by setting
a break point and calling them in your watch window (I prefer doing that over the
immediate window).&lt;br&gt;
&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;///
&amp;lt;summary&amp;gt;&lt;/span&gt; &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;///
Returns a rough approximation of the size of an object 
&lt;br&gt;
/// (including ALL objects in/directly referenced by the object)&lt;/span&gt; &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;///
&amp;lt;/summary&amp;gt;&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;static&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;long&lt;/span&gt; ApproxSize(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;object&lt;/span&gt; obj)
{ BinaryFormatter formatter &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;new&lt;/span&gt; BinaryFormatter(); &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;long&lt;/span&gt; length; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;using&lt;/span&gt; (MemoryStream
stream &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;new&lt;/span&gt; MemoryStream())
{ formatter.Serialize(stream, obj); stream.Seek(0, SeekOrigin.Begin); length &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; stream.Length;
} &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;return&lt;/span&gt; length;
} &lt;/span&gt;&lt;/pre&gt;
&lt;br&gt;
Sometimes though, your object is very large and serializing the object in memory will
cause an OutOfMemory Exception. So use the below method instead, it serializes the
object to disk and gives you the size of the file (and deletes the file after its
done). 
&lt;br&gt;
&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;///
&amp;lt;summary&amp;gt;&lt;br&gt;
/// Returns the approximate size of very large objects 
&lt;br&gt;
/// (time intensive) in bytes.&lt;br&gt;
/// &amp;lt;/summary&amp;gt;&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;static&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;long&lt;/span&gt; ApproxSizeLarge(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;object&lt;/span&gt; obj)
{ FileInfo info &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;new&lt;/span&gt; FileInfo(&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;@"c:\approxSizeTemp"&lt;/span&gt;);
BinaryFormatter formatter &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;new&lt;/span&gt; BinaryFormatter(); &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;using&lt;/span&gt; (StreamWriter
writer &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;new&lt;/span&gt; StreamWriter(&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;@"c:\approxSizeTemp"&lt;/span&gt;))
{ formatter.Serialize(writer.BaseStream, obj); } &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;long&lt;/span&gt; length &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; info.Length;
info.Delete(); &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;return&lt;/span&gt; length;
}&lt;/span&gt;&lt;/pre&gt;
&lt;br&gt;
&lt;p&gt;
&lt;/p&gt;</description>
      <comments>http://www.vonsharp.net/CommentView,guid,c8ff4f30-3dbd-427a-88ea-7252e5219a22.aspx</comments>
      <category>Tips and Tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.vonsharp.net/Trackback.aspx?guid=f7bea287-6eb1-4e1e-8965-98a7c8eafe7a</trackback:ping>
      <pingback:server>http://www.vonsharp.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.vonsharp.net/PermaLink,guid,f7bea287-6eb1-4e1e-8965-98a7c8eafe7a.aspx</pingback:target>
      <dc:creator>von</dc:creator>
      <wfw:comment>http://www.vonsharp.net/CommentView,guid,f7bea287-6eb1-4e1e-8965-98a7c8eafe7a.aspx</wfw:comment>
      <wfw:commentRss>http://www.vonsharp.net/SyndicationService.asmx/GetEntryCommentsRss?guid=f7bea287-6eb1-4e1e-8965-98a7c8eafe7a</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">So I was never really expecting to make
much money from my AdSense advertisements, if I made $10 in a year, I'd be happy.
But perhaps I've only made 80 cents thus far because Google is serving absurd ads
like:<br /><br /><p></p><img src="http://www.vonsharp.net/content/binary/crappy%20adsense%20ad.png" border="0" /><br /><br />
What AdWords did these people buy that is displayed on my site talking about Microsoft
Technologies? Is this some sort of joke perpetrated the FOSS Commie Zealots? My content
might be a little crappy (<a href="http://www.dotnetkicks.com/zeitgeist/2008/2">or
not</a>) but C#, WPF and LINQ are simply bad-ass.<br /></body>
      <title>What The Hell?</title>
      <guid isPermaLink="false">http://www.vonsharp.net/PermaLink,guid,f7bea287-6eb1-4e1e-8965-98a7c8eafe7a.aspx</guid>
      <link>http://www.vonsharp.net/WhatTheHell.aspx</link>
      <pubDate>Sat, 16 Feb 2008 17:07:21 GMT</pubDate>
      <description>So I was never really expecting to make much money from my AdSense advertisements, if I made $10 in a year, I'd be happy. But perhaps I've only made 80 cents thus far because Google is serving absurd ads like:&lt;br&gt;
&lt;br&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img src="http://www.vonsharp.net/content/binary/crappy%20adsense%20ad.png" border="0"&gt;
&lt;br&gt;
&lt;br&gt;
What AdWords did these people buy that is displayed on my site talking about Microsoft
Technologies? Is this some sort of joke perpetrated the FOSS Commie Zealots? My content
might be a little crappy (&lt;a href="http://www.dotnetkicks.com/zeitgeist/2008/2"&gt;or
not&lt;/a&gt;) but C#, WPF and LINQ are simply bad-ass.&lt;br&gt;</description>
      <comments>http://www.vonsharp.net/CommentView,guid,f7bea287-6eb1-4e1e-8965-98a7c8eafe7a.aspx</comments>
      <category>Stuff</category>
    </item>
    <item>
      <trackback:ping>http://www.vonsharp.net/Trackback.aspx?guid=01d51ea8-2072-40fc-9dc9-dc75b078732d</trackback:ping>
      <pingback:server>http://www.vonsharp.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.vonsharp.net/PermaLink,guid,01d51ea8-2072-40fc-9dc9-dc75b078732d.aspx</pingback:target>
      <dc:creator>von</dc:creator>
      <wfw:comment>http://www.vonsharp.net/CommentView,guid,01d51ea8-2072-40fc-9dc9-dc75b078732d.aspx</wfw:comment>
      <wfw:commentRss>http://www.vonsharp.net/SyndicationService.asmx/GetEntryCommentsRss?guid=01d51ea8-2072-40fc-9dc9-dc75b078732d</wfw:commentRss>
      <slash:comments>7</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">I'm sure there are plenty of you out there
who have your boss hankering to use some of that "Xml Stuff". Sometimes we get sheltered
in our own little world and haven't actually had to work with a whole lot of xml data
that wasn't already wrapped up by the Project Settings object created by Visual Studio.
So naturally, you'd probably go to the "<a title="tubes" href="http://www.urbandictionary.com/define.php?term=intertubes" id="t59e">tubes</a>"
and search for some additional information. Undoubtedly, you will run across pages
telling you how to construct some Xml in C# by creating a new XmlDocument and adding
XmlNode children which will have attributes and subnodes and namespaces, ad infinitum.
And you'll realize you now have some of the world's fugliest code. So you decide,
"oh, well xml is really similar to html, I'll just build it using a StringBuilder"
and you end up with slightly less fugly code, that is until you try to read it back
in.<br /><br />
These methods are completely unnecessary. PUT DOWN THE XMLNODE AND STEP AWAY FROM
THE STRINGBUILDER. Slowly move your hand to the mouse and scroll down to read about
the easiest way to write <b>and </b>read Xml in the .net framework. 
<br /><br />
Ok, quick show of hands: who thinks working with simple .net business model objects
is brain dead easy? Alright, if your hand isn't up, you are beyond hope, please leave
now. Of course, working with simple objects is about the simplest exercise for code
next to "Hello World". If you can create a .net object that models the xml you want
to store, you are 95% done with outputting well formed Xml. 
<br /><br />
Example: If I wanted to store information about a few people and their pets I would
create three classes:<br /><pre><span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">public</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">class</span> PetClub<br />
{<br /><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">public</span> List&lt;Person&gt;
Members { get; set; }<br />
}<br /><br /><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">public</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">class</span> Person<br />
{<br /><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">public</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">string</span> Name
{ get; set; }<br /><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">public</span> List&lt;Pet&gt;
Pets { get; set; }<br />
}<br /><br /><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">public</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">class</span> Pet<br />
{<br /><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">public</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">string</span> Name
{ get; set; }<br /><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">public</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">string</span> Type
{ get; set; }<br />
}</span></pre>
To get an Xml representation of an instance of PetClub, all you have to do is use
the XmlSerializer found in the System.Xml.Serialization namespace. I've wrapped up
all the necessary code into a short utility method.<br /><pre><span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">public</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">static</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">string</span> ConvertToXml(<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">object</span> item)<br />
{<br />
XmlSerializer xmlser <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">new</span> XmlSerializer(item.GetType());<br /><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">using</span> (System.IO.MemoryStream
ms <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">new</span> System.IO.MemoryStream())<br />
{<br />
xmlser.Serialize(ms, item);<br />
UTF8Encoding textconverter <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">new</span> UTF8Encoding();<br /><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">return</span> textconverter.GetString(ms.ToArray());<br />
}<br />
}</span></pre><br />
Simply calling: ConvertToXml(myPetClubInstance) will spit back the following xml:<br /><br /><font face="Courier New">&lt;PetClub xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;<br />
  &lt;Members&gt;<br />
    &lt;Person&gt;<br />
      &lt;Name&gt;Jon&lt;/Name&gt;<br />
      &lt;Pets&gt;<br />
        &lt;Pet&gt;<br />
          &lt;Name&gt;Chester&lt;/Name&gt;<br />
          &lt;Type&gt;Savannah Cat&lt;/Type&gt;<br />
        &lt;/Pet&gt;<br />
        &lt;Pet&gt;<br />
          &lt;Name&gt;Abby&lt;/Name&gt;<br />
          &lt;Type&gt;Domestic Miniature
Panther&lt;/Type&gt;<br />
        &lt;/Pet&gt;<br />
      &lt;/Pets&gt;<br />
    &lt;/Person&gt;<br />
    &lt;Person&gt;<br />
      &lt;Name&gt;Dan&lt;/Name&gt;<br />
      &lt;Pets&gt;<br />
        &lt;Pet&gt;<br />
          &lt;Name&gt;Lucy&lt;/Name&gt;<br />
          &lt;Type&gt;Semi-sweet Chocolate
Lab&lt;/Type&gt;<br />
        &lt;/Pet&gt;<br />
      &lt;/Pets&gt;<br />
    &lt;/Person&gt;<br />
  &lt;/Members&gt;<br />
&lt;/PetClub&gt;</font><br /><br />
At this point you might be saying: "That is cool and all, Jon, but this looks like
a lot of xml to be outputting for such little actual data. And what if I want to have
more control over xml element naming". Dear friend, let not your heart be troubled
for there is help on the way. By adding some simple Property Attributes to our classes
we can completely change how our xml is constructed.  We can have the object
in whatever form is most convienient for our program while still allowing us to interoperate
with an xml document created by a different application with a different idea of what
good names are.<br /><br />
Changing our two classes to:<br /><pre><span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">public</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">class</span> Person<br />
{<br />
[XmlElement(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"FirstName"</span>)]<br /><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">public</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">string</span> Name
{ get; set; }<br /><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">public</span> List&lt;Pet&gt;
Pets { get; set; }<br />
}<br /><br /><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">public</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">class</span> Pet<br />
{<br />
[XmlAttribute(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"Name"</span>)]<br /><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">public</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">string</span> Name
{ get; set; }<br />
[XmlAttribute(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"Breed"</span>)]<br /><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">public</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">string</span> Type
{ get; set; }<br />
} </span></pre><br />
Will output this xml:<br /><br /><font face="Courier New"> &lt;PetClub xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;<br />
  &lt;Members&gt;<br />
    &lt;Person&gt;<br />
      &lt;FirstName&gt;Jon&lt;/FirstName&gt;<br />
      &lt;Pets&gt;<br />
        &lt;Pet Name="Chester" Breed="Savannah
Cat" /&gt;<br />
        &lt;Pet Name="Abby" Breed="Domestic Miniature
Panther" /&gt;<br />
      &lt;/Pets&gt;<br />
    &lt;/Person&gt;<br />
    &lt;Person&gt;<br />
      &lt;FirstName&gt;Dan&lt;/FirstName&gt;<br />
      &lt;Pets&gt;<br />
        &lt;Pet Name="Lucy" Breed="Semi-sweet Chocolate
Lab" /&gt;<br />
      &lt;/Pets&gt;<br />
    &lt;/Person&gt;<br />
  &lt;/Members&gt;<br />
&lt;/PetClub&gt;</font><br /><br /><br />
Pretty simple, huh? Can you imagine how difficult it would be to make these changes
via XmlNodes or a StringBuilder? There are about 10 other property attributes available
for xml serialization, including the very useful XmlIgnore() attribute which makes
the appropriate property not serialized. I'll leave the rest of the research up to
you. 
<br /><br />
And I almost forgot, to read your xml back into an object use the following method:<br /><pre><span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"><br /><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">public</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">static</span> T
FromXml&lt;T&gt;(<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">string</span> xml)<br />
{<br />
XmlSerializer xmlser <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">new</span> XmlSerializer(<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">typeof</span>(T));<br /><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">using</span> (System.IO.StringReader
sr <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">new</span> System.IO.StringReader(xml))<br />
{<br /><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">return</span> (T)xmlser.Deserialize(sr);<br />
}<br />
}<br /></span></pre><h1><span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"></span></h1><p></p>
Sample Code - <a href="http://www.vonsharp.net/content/binary/XmlSerializerSample.%5Brename%20to%20cs%5D" temp_href="http://www.vonsharp.net/content/binary/XmlSerializerSample.[rename to cs]">XmlSerializerSample.cs
(2.33 KB)</a><br /><br /></body>
      <title>Put Down the XmlNode and Step Away From the StringBuilder</title>
      <guid isPermaLink="false">http://www.vonsharp.net/PermaLink,guid,01d51ea8-2072-40fc-9dc9-dc75b078732d.aspx</guid>
      <link>http://www.vonsharp.net/PutDownTheXmlNodeAndStepAwayFromTheStringBuilder.aspx</link>
      <pubDate>Tue, 12 Feb 2008 14:29:33 GMT</pubDate>
      <description>I'm sure there are plenty of you out there who have your boss hankering
to use some of that "Xml Stuff". Sometimes we get sheltered in our own
little world and haven't actually had to work with a whole lot of xml
data that wasn't already wrapped up by the Project Settings object
created by Visual Studio. So naturally, you'd probably go to the "&lt;a title="tubes" href="http://www.urbandictionary.com/define.php?term=intertubes" id="t59e"&gt;tubes&lt;/a&gt;"
and search for some additional information. Undoubtedly, you will run across pages
telling you how to construct some Xml in C# by creating a new XmlDocument and adding
XmlNode children which will have attributes and subnodes and namespaces, ad infinitum.
And you'll realize you now have some of the world's fugliest code. So you decide,
"oh, well xml is really similar to html, I'll just build it using a StringBuilder"
and you end up with slightly less fugly code, that is until you try to read it back
in.&lt;br&gt;
&lt;br&gt;
These methods are completely unnecessary. PUT DOWN THE XMLNODE AND STEP AWAY FROM
THE STRINGBUILDER. Slowly move your hand to the mouse and scroll down to read about
the easiest way to write &lt;b&gt;and &lt;/b&gt;read Xml in the .net framework. 
&lt;br&gt;
&lt;br&gt;
Ok, quick show of hands: who thinks working with simple .net business model objects
is brain dead easy? Alright, if your hand isn't up, you are beyond hope, please leave
now. Of course, working with simple objects is about the simplest exercise for code
next to "Hello World". If you can create a .net object that models the xml you want
to store, you are 95% done with outputting well formed Xml. 
&lt;br&gt;
&lt;br&gt;
Example: If I wanted to store information about a few people and their pets I would
create three classes:&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;class&lt;/span&gt; PetClub&lt;br&gt;
{&lt;br&gt;
&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt; List&amp;lt;Person&amp;gt;
Members { get; set; }&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;class&lt;/span&gt; Person&lt;br&gt;
{&lt;br&gt;
&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;string&lt;/span&gt; Name
{ get; set; }&lt;br&gt;
&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt; List&amp;lt;Pet&amp;gt;
Pets { get; set; }&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;class&lt;/span&gt; Pet&lt;br&gt;
{&lt;br&gt;
&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;string&lt;/span&gt; Name
{ get; set; }&lt;br&gt;
&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;string&lt;/span&gt; Type
{ get; set; }&lt;br&gt;
}&lt;/span&gt;&lt;/pre&gt;
To get an Xml representation of an instance of PetClub, all you have to do is use
the XmlSerializer found in the System.Xml.Serialization namespace. I've wrapped up
all the necessary code into a short utility method.&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;static&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;string&lt;/span&gt; ConvertToXml(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;object&lt;/span&gt; item)&lt;br&gt;
{&lt;br&gt;
XmlSerializer xmlser &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;new&lt;/span&gt; XmlSerializer(item.GetType());&lt;br&gt;
&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;using&lt;/span&gt; (System.IO.MemoryStream
ms &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;new&lt;/span&gt; System.IO.MemoryStream())&lt;br&gt;
{&lt;br&gt;
xmlser.Serialize(ms, item);&lt;br&gt;
UTF8Encoding textconverter &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;new&lt;/span&gt; UTF8Encoding();&lt;br&gt;
&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;return&lt;/span&gt; textconverter.GetString(ms.ToArray());&lt;br&gt;
}&lt;br&gt;
}&lt;/span&gt;&lt;/pre&gt;
&lt;br&gt;
Simply calling: ConvertToXml(myPetClubInstance) will spit back the following xml:&lt;br&gt;
&lt;br&gt;
&lt;font face="Courier New"&gt;&amp;lt;PetClub xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"&amp;gt;&lt;br&gt;
&amp;nbsp; &amp;lt;Members&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Person&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Name&amp;gt;Jon&amp;lt;/Name&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Pets&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Pet&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Name&amp;gt;Chester&amp;lt;/Name&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Type&amp;gt;Savannah Cat&amp;lt;/Type&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/Pet&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Pet&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Name&amp;gt;Abby&amp;lt;/Name&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Type&amp;gt;Domestic Miniature
Panther&amp;lt;/Type&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/Pet&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/Pets&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/Person&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Person&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Name&amp;gt;Dan&amp;lt;/Name&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Pets&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Pet&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Name&amp;gt;Lucy&amp;lt;/Name&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Type&amp;gt;Semi-sweet Chocolate
Lab&amp;lt;/Type&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/Pet&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/Pets&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/Person&amp;gt;&lt;br&gt;
&amp;nbsp; &amp;lt;/Members&amp;gt;&lt;br&gt;
&amp;lt;/PetClub&amp;gt;&lt;/font&gt;
&lt;br&gt;
&lt;br&gt;
At this point you might be saying: "That is cool and all, Jon, but this looks like
a lot of xml to be outputting for such little actual data. And what if I want to have
more control over xml element naming". Dear friend, let not your heart be troubled
for there is help on the way. By adding some simple Property Attributes to our classes
we can completely change how our xml is constructed.&amp;nbsp; We can have the object
in whatever form is most convienient for our program while still allowing us to interoperate
with an xml document created by a different application with a different idea of what
good names are.&lt;br&gt;
&lt;br&gt;
Changing our two classes to:&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;class&lt;/span&gt; Person&lt;br&gt;
{&lt;br&gt;
[XmlElement(&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"FirstName"&lt;/span&gt;)]&lt;br&gt;
&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;string&lt;/span&gt; Name
{ get; set; }&lt;br&gt;
&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt; List&amp;lt;Pet&amp;gt;
Pets { get; set; }&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;class&lt;/span&gt; Pet&lt;br&gt;
{&lt;br&gt;
[XmlAttribute(&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Name"&lt;/span&gt;)]&lt;br&gt;
&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;string&lt;/span&gt; Name
{ get; set; }&lt;br&gt;
[XmlAttribute(&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Breed"&lt;/span&gt;)]&lt;br&gt;
&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;string&lt;/span&gt; Type
{ get; set; }&lt;br&gt;
} &lt;/span&gt;&lt;/pre&gt;
&lt;br&gt;
Will output this xml:&lt;br&gt;
&lt;br&gt;
&lt;font face="Courier New"&gt; &amp;lt;PetClub xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"&amp;gt;&lt;br&gt;
&amp;nbsp; &amp;lt;Members&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Person&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;FirstName&amp;gt;Jon&amp;lt;/FirstName&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Pets&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Pet Name="Chester" Breed="Savannah
Cat" /&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Pet Name="Abby" Breed="Domestic Miniature
Panther" /&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/Pets&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/Person&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Person&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;FirstName&amp;gt;Dan&amp;lt;/FirstName&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Pets&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Pet Name="Lucy" Breed="Semi-sweet Chocolate
Lab" /&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/Pets&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/Person&amp;gt;&lt;br&gt;
&amp;nbsp; &amp;lt;/Members&amp;gt;&lt;br&gt;
&amp;lt;/PetClub&amp;gt;&lt;/font&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Pretty simple, huh? Can you imagine how difficult it would be to make these changes
via XmlNodes or a StringBuilder? There are about 10 other property attributes available
for xml serialization, including the very useful XmlIgnore() attribute which makes
the appropriate property not serialized. I'll leave the rest of the research up to
you. 
&lt;br&gt;
&lt;br&gt;
And I almost forgot, to read your xml back into an object use the following method:&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;
&lt;br&gt;
&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;static&lt;/span&gt; T
FromXml&amp;lt;T&amp;gt;(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;string&lt;/span&gt; xml)&lt;br&gt;
{&lt;br&gt;
XmlSerializer xmlser &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;new&lt;/span&gt; XmlSerializer(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;typeof&lt;/span&gt;(T));&lt;br&gt;
&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;using&lt;/span&gt; (System.IO.StringReader
sr &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;new&lt;/span&gt; System.IO.StringReader(xml))&lt;br&gt;
{&lt;br&gt;
&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;return&lt;/span&gt; (T)xmlser.Deserialize(sr);&lt;br&gt;
}&lt;br&gt;
}&lt;br&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;h1&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;/span&gt;
&lt;/h1&gt;
&lt;p&gt;
&lt;/p&gt;
Sample Code - &lt;a href="http://www.vonsharp.net/content/binary/XmlSerializerSample.%5Brename%20to%20cs%5D" temp_href="http://www.vonsharp.net/content/binary/XmlSerializerSample.[rename to cs]"&gt;XmlSerializerSample.cs
(2.33 KB)&lt;/a&gt;
&lt;br&gt;
&lt;br&gt;</description>
      <comments>http://www.vonsharp.net/CommentView,guid,01d51ea8-2072-40fc-9dc9-dc75b078732d.aspx</comments>
      <category>Tips and Tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.vonsharp.net/Trackback.aspx?guid=fa13cb82-1f8d-4fec-bf61-10df57731a11</trackback:ping>
      <pingback:server>http://www.vonsharp.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.vonsharp.net/PermaLink,guid,fa13cb82-1f8d-4fec-bf61-10df57731a11.aspx</pingback:target>
      <dc:creator>von</dc:creator>
      <wfw:comment>http://www.vonsharp.net/CommentView,guid,fa13cb82-1f8d-4fec-bf61-10df57731a11.aspx</wfw:comment>
      <wfw:commentRss>http://www.vonsharp.net/SyndicationService.asmx/GetEntryCommentsRss?guid=fa13cb82-1f8d-4fec-bf61-10df57731a11</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">Well, as you can tell I've got a new DasBlog
theme I created myself. I'm not the most artistic person in the world, but I'm happy
with what I've accomplished. Good lord did it take a long time, its been a while since
I've pounded out HTML and CSS, but I'm glad to have it fresh in my head again but
I'm totally disgusted at how differently IE and Firefox render, what a gigantic waste
of time. 
<br /><br />
Have a good week!<br /><p></p></body>
      <title>Custom Created Theme</title>
      <guid isPermaLink="false">http://www.vonsharp.net/PermaLink,guid,fa13cb82-1f8d-4fec-bf61-10df57731a11.aspx</guid>
      <link>http://www.vonsharp.net/CustomCreatedTheme.aspx</link>
      <pubDate>Mon, 11 Feb 2008 05:47:16 GMT</pubDate>
      <description>Well, as you can tell I've got a new DasBlog theme I created myself. I'm not the most artistic person in the world, but I'm happy with what I've accomplished. Good lord did it take a long time, its been a while since I've pounded out HTML and CSS, but I'm glad to have it fresh in my head again but I'm totally disgusted at how differently IE and Firefox render, what a gigantic waste of time. &lt;br&gt;
&lt;br&gt;
Have a good week!&lt;br&gt;
&lt;p&gt;
&lt;/p&gt;</description>
      <comments>http://www.vonsharp.net/CommentView,guid,fa13cb82-1f8d-4fec-bf61-10df57731a11.aspx</comments>
      <category>Stuff</category>
    </item>
    <item>
      <trackback:ping>http://www.vonsharp.net/Trackback.aspx?guid=482fcfaa-f3c6-4a1f-a21c-b3cf7f0e7a1b</trackback:ping>
      <pingback:server>http://www.vonsharp.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.vonsharp.net/PermaLink,guid,482fcfaa-f3c6-4a1f-a21c-b3cf7f0e7a1b.aspx</pingback:target>
      <dc:creator>von</dc:creator>
      <wfw:comment>http://www.vonsharp.net/CommentView,guid,482fcfaa-f3c6-4a1f-a21c-b3cf7f0e7a1b.aspx</wfw:comment>
      <wfw:commentRss>http://www.vonsharp.net/SyndicationService.asmx/GetEntryCommentsRss?guid=482fcfaa-f3c6-4a1f-a21c-b3cf7f0e7a1b</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">That is all.<br /><p></p></body>
      <title>Damn It Feels Good To Write Unit Tests Again</title>
      <guid isPermaLink="false">http://www.vonsharp.net/PermaLink,guid,482fcfaa-f3c6-4a1f-a21c-b3cf7f0e7a1b.aspx</guid>
      <link>http://www.vonsharp.net/DamnItFeelsGoodToWriteUnitTestsAgain.aspx</link>
      <pubDate>Fri, 08 Feb 2008 18:45:33 GMT</pubDate>
      <description>That is all.&lt;br&gt;
&lt;p&gt;
&lt;/p&gt;</description>
      <comments>http://www.vonsharp.net/CommentView,guid,482fcfaa-f3c6-4a1f-a21c-b3cf7f0e7a1b.aspx</comments>
      <category>Stuff</category>
    </item>
    <item>
      <trackback:ping>http://www.vonsharp.net/Trackback.aspx?guid=1cc24b4b-cfdb-46f2-af0d-320ce151fb19</trackback:ping>
      <pingback:server>http://www.vonsharp.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.vonsharp.net/PermaLink,guid,1cc24b4b-cfdb-46f2-af0d-320ce151fb19.aspx</pingback:target>
      <dc:creator>von</dc:creator>
      <wfw:comment>http://www.vonsharp.net/CommentView,guid,1cc24b4b-cfdb-46f2-af0d-320ce151fb19.aspx</wfw:comment>
      <wfw:commentRss>http://www.vonsharp.net/SyndicationService.asmx/GetEntryCommentsRss?guid=1cc24b4b-cfdb-46f2-af0d-320ce151fb19</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">It really does shock and amaze me how many
developers get through the day without knowing the wonders of the Exceptions Dialog
box. You can access it via Debug&gt;Exceptions or you can hit Ctrl-Alt-E. What this
dialog box allows you do is to pick a set of exceptions (or all of them for that matter)
and the debugger will automatically break when the exception is thrown. This allows
you to inspect your call stack and interrogate your variables to determine the state
of your application when the exception occurred. No longer do you have to look through
an error message to find a line number and start setting break points. This becomes
especially helpful if the error is occurring in a gigantic loop and your not sure
how many times the loop executes before it runs into a null reference exception. It
breaks automatically and voila, you can easily see all the variables that are associated
with your null object (or whatever the error may be).<br /><br />
Sometimes you'll be responsible for code, that for one reason or another uses exception
catching/handling as a normal part of code flow. This usually is considered a bad
practice but sometimes you don't have a choice under the circumstances. When that
happens, it is very easy to turn off custom typed exceptions, just click the "Add..."
button and type in the fully qualified name of the exception you don't want to see
every time it is thrown. As you can see in my screenshot, I've done this with the
Sybase.Data.AseClient.AseException exception. 
<br /><br />
I hope this helps speed up any future debugging.<br /><br /><br /><p></p><img src="http://www.vonsharp.net/content/binary/ExceptionsDialogBox2.jpg" border="0" /></body>
      <title>Most Useful VS Feature No One Knows About</title>
      <guid isPermaLink="false">http://www.vonsharp.net/PermaLink,guid,1cc24b4b-cfdb-46f2-af0d-320ce151fb19.aspx</guid>
      <link>http://www.vonsharp.net/MostUsefulVSFeatureNoOneKnowsAbout.aspx</link>
      <pubDate>Thu, 07 Feb 2008 17:23:45 GMT</pubDate>
      <description>It really does shock and amaze me how many developers get through the day without knowing the wonders of the Exceptions Dialog box. You can access it via Debug&amp;gt;Exceptions or you can hit Ctrl-Alt-E. What this dialog box allows you do is to pick a set of exceptions (or all of them for that matter) and the debugger will automatically break when the exception is thrown. This allows you to inspect your call stack and interrogate your variables to determine the state of your application when the exception occurred. No longer do you have to look through an error message to find a line number and start setting break points. This becomes especially helpful if the error is occurring in a gigantic loop and your not sure how many times the loop executes before it runs into a null reference exception. It breaks automatically and voila, you can easily see all the variables that are associated with your null object (or whatever the error may be).&lt;br&gt;
&lt;br&gt;
Sometimes you'll be responsible for code, that for one reason or another uses exception
catching/handling as a normal part of code flow. This usually is considered a bad
practice but sometimes you don't have a choice under the circumstances. When that
happens, it is very easy to turn off custom typed exceptions, just click the "Add..."
button and type in the fully qualified name of the exception you don't want to see
every time it is thrown. As you can see in my screenshot, I've done this with the
Sybase.Data.AseClient.AseException exception. 
&lt;br&gt;
&lt;br&gt;
I hope this helps speed up any future debugging.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img src="http://www.vonsharp.net/content/binary/ExceptionsDialogBox2.jpg" border="0"&gt;</description>
      <comments>http://www.vonsharp.net/CommentView,guid,1cc24b4b-cfdb-46f2-af0d-320ce151fb19.aspx</comments>
      <category>Tips and Tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.vonsharp.net/Trackback.aspx?guid=460688c0-11c1-477f-87cb-855cdba1ccc7</trackback:ping>
      <pingback:server>http://www.vonsharp.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.vonsharp.net/PermaLink,guid,460688c0-11c1-477f-87cb-855cdba1ccc7.aspx</pingback:target>
      <dc:creator>von</dc:creator>
      <wfw:comment>http://www.vonsharp.net/CommentView,guid,460688c0-11c1-477f-87cb-855cdba1ccc7.aspx</wfw:comment>
      <wfw:commentRss>http://www.vonsharp.net/SyndicationService.asmx/GetEntryCommentsRss?guid=460688c0-11c1-477f-87cb-855cdba1ccc7</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">I just found this site off of dotnetkicks,
and it looks like a great reference site for information on patterns and anti-patterns<br /><br /><a href="http://sourcemaking.com/">http://sourcemaking.com/</a><br /><p></p></body>
      <title>Patterns</title>
      <guid isPermaLink="false">http://www.vonsharp.net/PermaLink,guid,460688c0-11c1-477f-87cb-855cdba1ccc7.aspx</guid>
      <link>http://www.vonsharp.net/Patterns.aspx</link>
      <pubDate>Mon, 04 Feb 2008 14:46:19 GMT</pubDate>
      <description>I just found this site off of dotnetkicks, and it looks like a great reference site for information on patterns and anti-patterns&lt;br&gt;
&lt;br&gt;
&lt;a href="http://sourcemaking.com/"&gt;http://sourcemaking.com/&lt;/a&gt;
&lt;br&gt;
&lt;p&gt;
&lt;/p&gt;</description>
      <comments>http://www.vonsharp.net/CommentView,guid,460688c0-11c1-477f-87cb-855cdba1ccc7.aspx</comments>
    </item>
    <item>
      <trackback:ping>http://www.vonsharp.net/Trackback.aspx?guid=4cc182ab-3611-4d0f-bea4-3a921e71dd16</trackback:ping>
      <pingback:server>http://www.vonsharp.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.vonsharp.net/PermaLink,guid,4cc182ab-3611-4d0f-bea4-3a921e71dd16.aspx</pingback:target>
      <dc:creator>von</dc:creator>
      <wfw:comment>http://www.vonsharp.net/CommentView,guid,4cc182ab-3611-4d0f-bea4-3a921e71dd16.aspx</wfw:comment>
      <wfw:commentRss>http://www.vonsharp.net/SyndicationService.asmx/GetEntryCommentsRss?guid=4cc182ab-3611-4d0f-bea4-3a921e71dd16</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">Generic dictionaries are a great thing,
they let you add and retrieve objects very quickly. My current gig has a lot of need
for them because we've got tons of data that needs to be quickly referenced (I'll
post more about Dictionary memory performance later). The problem is that developers
everywhere like to use very un-descriptive names for their dictionaries, especially
nested dictionaries. Usually you'd like to avoid nesting these things, but sometimes
you don't have a choice and making a bunch of derived classes adds a lot of code and
more "stuff" you have to sift through.<br /><br />
Simple Example:<br /><pre><span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;">Dictionary&lt;<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span>, <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">string</span>&gt;
_peopleDictionary;</span></pre>
What is the key? Is it a PersonId? Is it a CustomerId? Is it an EmployeeId? Is it
a Social Security Number?<br /><br />
What about the value? Is it First Name, Last Name, First then Last, Last then First,
Nickname?<br /><br />
In order to find out, a developer who takes over your code has to look up all references
to PeopleDictionary and find out what the Key and Values are, yielding a gigantic
waste of time. (Worse yet, it could be you looking up all the references because you
haven't looked at this particular code in 7 months). And that is even a non-nested
dictionary!<br /><br />
Now, can you tell me what kind of data is stored in the below object?<br /><pre><span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;">Dictionary&lt;<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span>,
Dictionary&lt;<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span>,
List&lt;<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">string</span>&gt;&gt;&gt;
_customerIdToOrderIdToDescriptions;</span></pre>
Sure the name is a little long, but think about how many different kinds of data are
being stored in it. Plus you didn't have to make a custom object for a one-off need.
Anyone who has to modify your code can easily use this object without trying to figure
out what "OrdersDictionary" is actually storing. 
<br /><br />
FXCop Guys: I'll give you $10 if you add a rule saying that generic dictionary variable
names have to contain the string literal "To".<br /><br />
Of note: it's generally considered bad practice to use nested generics, but if you
do, just make sure that you don't expose nested generic types by returning them in
public methods or by making a public property with a nested type. Keep them for internal
use within your class only.<br /><br /><p></p></body>
      <title>Dictionary Naming Guidelines</title>
      <guid isPermaLink="false">http://www.vonsharp.net/PermaLink,guid,4cc182ab-3611-4d0f-bea4-3a921e71dd16.aspx</guid>
      <link>http://www.vonsharp.net/DictionaryNamingGuidelines.aspx</link>
      <pubDate>Wed, 23 Jan 2008 16:05:02 GMT</pubDate>
      <description>Generic dictionaries are a great thing, they let you add and retrieve objects very quickly. My current gig has a lot of need for them because we've got tons of data that needs to be quickly referenced (I'll post more about Dictionary memory performance later). The problem is that developers everywhere like to use very un-descriptive names for their dictionaries, especially nested dictionaries. Usually you'd like to avoid nesting these things, but sometimes you don't have a choice and making a bunch of derived classes adds a lot of code and more "stuff" you have to sift through.&lt;br&gt;
&lt;br&gt;
Simple Example:&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;Dictionary&amp;lt;&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt;, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;string&lt;/span&gt;&amp;gt;
_peopleDictionary;&lt;/span&gt;&lt;/pre&gt;
What is the key? Is it a PersonId? Is it a CustomerId? Is it an EmployeeId? Is it
a Social Security Number?&lt;br&gt;
&lt;br&gt;
What about the value? Is it First Name, Last Name, First then Last, Last then First,
Nickname?&lt;br&gt;
&lt;br&gt;
In order to find out, a developer who takes over your code has to look up all references
to PeopleDictionary and find out what the Key and Values are, yielding a gigantic
waste of time. (Worse yet, it could be you looking up all the references because you
haven't looked at this particular code in 7 months). And that is even a non-nested
dictionary!&lt;br&gt;
&lt;br&gt;
Now, can you tell me what kind of data is stored in the below object?&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;Dictionary&amp;lt;&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt;,
Dictionary&amp;lt;&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt;,
List&amp;lt;&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;string&lt;/span&gt;&amp;gt;&amp;gt;&amp;gt;
_customerIdToOrderIdToDescriptions;&lt;/span&gt;&lt;/pre&gt;
Sure the name is a little long, but think about how many different kinds of data are
being stored in it. Plus you didn't have to make a custom object for a one-off need.
Anyone who has to modify your code can easily use this object without trying to figure
out what "OrdersDictionary" is actually storing. 
&lt;br&gt;
&lt;br&gt;
FXCop Guys: I'll give you $10 if you add a rule saying that generic dictionary variable
names have to contain the string literal "To".&lt;br&gt;
&lt;br&gt;
Of note: it's generally considered bad practice to use nested generics, but if you
do, just make sure that you don't expose nested generic types by returning them in
public methods or by making a public property with a nested type. Keep them for internal
use within your class only.&lt;br&gt;
&lt;br&gt;
&lt;p&gt;
&lt;/p&gt;</description>
      <comments>http://www.vonsharp.net/CommentView,guid,4cc182ab-3611-4d0f-bea4-3a921e71dd16.aspx</comments>
      <category>Tips and Tricks</category>
      <category>Wishlist</category>
    </item>
    <item>
      <trackback:ping>http://www.vonsharp.net/Trackback.aspx?guid=a3fb8bcc-9e2e-478b-9a73-a4aad99141b0</trackback:ping>
      <pingback:server>http://www.vonsharp.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.vonsharp.net/PermaLink,guid,a3fb8bcc-9e2e-478b-9a73-a4aad99141b0.aspx</pingback:target>
      <dc:creator>von</dc:creator>
      <wfw:comment>http://www.vonsharp.net/CommentView,guid,a3fb8bcc-9e2e-478b-9a73-a4aad99141b0.aspx</wfw:comment>
      <wfw:commentRss>http://www.vonsharp.net/SyndicationService.asmx/GetEntryCommentsRss?guid=a3fb8bcc-9e2e-478b-9a73-a4aad99141b0</wfw:commentRss>
      <slash:comments>5</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">Register and attend for your local launch
event and receive a free copy of Visual Studio 2008, SQL Server 2008 AND Windows Server
2008. Which by my estimate is at least $2000 in free software.<br /><br /><a href="http://www.microsoft.com/heroeshappenhere/register/default.mspx">http://www.microsoft.com/heroeshappenhere/register/default.mspx</a><br /><br />
(If you're feeling generous, I would accept a 10% finders fee)<br /><p></p></body>
      <title>Free Copy of VS 2008</title>
      <guid isPermaLink="false">http://www.vonsharp.net/PermaLink,guid,a3fb8bcc-9e2e-478b-9a73-a4aad99141b0.aspx</guid>
      <link>http://www.vonsharp.net/FreeCopyOfVS2008.aspx</link>
      <pubDate>Fri, 18 Jan 2008 19:33:04 GMT</pubDate>
      <description>Register and attend for your local launch event and receive a free copy of Visual Studio 2008, SQL Server 2008 AND Windows Server 2008. Which by my estimate is at least $2000 in free software.&lt;br&gt;
&lt;br&gt;
&lt;a href="http://www.microsoft.com/heroeshappenhere/register/default.mspx"&gt;http://www.microsoft.com/heroeshappenhere/register/default.mspx&lt;/a&gt;
&lt;br&gt;
&lt;br&gt;
(If you're feeling generous, I would accept a 10% finders fee)&lt;br&gt;
&lt;p&gt;
&lt;/p&gt;</description>
      <comments>http://www.vonsharp.net/CommentView,guid,a3fb8bcc-9e2e-478b-9a73-a4aad99141b0.aspx</comments>
      <category>Stuff</category>
    </item>
    <item>
      <trackback:ping>http://www.vonsharp.net/Trackback.aspx?guid=beb68c16-4e73-4dca-92c0-0dbfb35ddb85</trackback:ping>
      <pingback:server>http://www.vonsharp.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.vonsharp.net/PermaLink,guid,beb68c16-4e73-4dca-92c0-0dbfb35ddb85.aspx</pingback:target>
      <dc:creator>von</dc:creator>
      <wfw:comment>http://www.vonsharp.net/CommentView,guid,beb68c16-4e73-4dca-92c0-0dbfb35ddb85.aspx</wfw:comment>
      <wfw:commentRss>http://www.vonsharp.net/SyndicationService.asmx/GetEntryCommentsRss?guid=beb68c16-4e73-4dca-92c0-0dbfb35ddb85</wfw:commentRss>
      <slash:comments>3</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">Do you ever get sick of having to write
4 whole lines for timing certain parts of your code. I know 4 lines isn't that bad,
but they multiply quickly when you're testing a lot of different code, or different
parts of the same method. That is why I came up with a StopwatchWriter class, it implements
IDisposable so you can use it in a using statement which reduces the needed code to
one line, put at the top of the code your testing (as opposed to before to setup and
after to write). The constructor starts a stopwatch and when the Dispose method gets
called, it stops the stopwatch and writes the time to the console, but it could easily
be changed to write any type of log.<br /><br />
public class StopwatchWriter : IDisposable<br />
{<br />
    Stopwatch _stopwatch = new Stopwatch();<br />
    string _text;<br /><br />
    public StopwatchWriter(string text)<br />
    {<br />
        _text = text + " - ";<br />
        _stopwatch.Start();<br />
    }<br /><br />
    public void Dispose()<br />
    {<br />
        _stopwatch.Stop();<br />
        Console.WriteLine("stopw: "+_text + _stopwatch.ElapsedMilliseconds);<br />
    }<br />
}<br /><br />
Usage looks like:<br /><br />
using (new StopwatchWriter("populateStuff"))<br />
{<br />
    this.PopulateStep1();<br />
    this.PopulateStep2();<br />
}<br /><br />
-or-<br /><br />
using (new StopwatchWriter("doStuff"))<br />
    DoStuff();<br /><br /><br /><br /><p></p></body>
      <title>StopwatchWriter Class</title>
      <guid isPermaLink="false">http://www.vonsharp.net/PermaLink,guid,beb68c16-4e73-4dca-92c0-0dbfb35ddb85.aspx</guid>
      <link>http://www.vonsharp.net/StopwatchWriterClass.aspx</link>
      <pubDate>Tue, 15 Jan 2008 15:06:25 GMT</pubDate>
      <description>Do you ever get sick of having to write 4 whole lines for timing certain parts of your code. I know 4 lines isn't that bad, but they multiply quickly when you're testing a lot of different code, or different parts of the same method. That is why I came up with a StopwatchWriter class, it implements IDisposable so you can use it in a using statement which reduces the needed code to one line, put at the top of the code your testing (as opposed to before to setup and after to write). The constructor starts a stopwatch and when the Dispose method gets called, it stops the stopwatch and writes the time to the console, but it could easily be changed to write any type of log.&lt;br&gt;
&lt;br&gt;
public class StopwatchWriter : IDisposable&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Stopwatch _stopwatch = new Stopwatch();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; string _text;&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; public StopwatchWriter(string text)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _text = text + " - ";&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _stopwatch.Start();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; public void Dispose()&lt;br