<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>General</title>
        <link>http://www.darkside.co.za/category/4.aspx</link>
        <description>Articles that I couldn't categorise, but have to do with development-related things</description>
        <language>en-ZA</language>
        <copyright>Ryan Schreiber</copyright>
        <generator>Subtext Version 2.1.0.5</generator>
        <item>
            <title>Compress and decompress a byte array</title>
            <link>http://www.darkside.co.za/archive/2010/05/11/compress-decompress-byte-array.aspx</link>
            <description>&lt;p&gt;A colleague asked me this morning if I already had a code snippet that compressed and decompressed byte arrays that he could make use of. He needed it to compress a variable before passing it as an argument to a WCF call, and decompress in the service itself. I’ve never made use of the System.IO.Compression namespace (I’d always used SharpZipLib), so I thought this would be a quick and useful experiment.&lt;/p&gt;  &lt;p&gt;After referencing the local MSDN and then the customary 30 second google, I decided I’d make my own, better, wheel :) I’m still convinced it’s less verbose than the first ten results I looked at, by the way. &lt;/p&gt;  &lt;p&gt;The compress part was easy enough (and follows the same logic as just about every example I found). What I couldn’t understand was why everyone implemented long-winded decompress routines. The answer to that question (found in MSDN) is that the Length property of the DeflateStream is not implemented and always throws an exception, meaning that you can’t determine the length of the byte array you’ll need.&lt;/p&gt;  &lt;p&gt;Here’s my quick-and-easy solution to the problem:  &lt;/p&gt;  &lt;div class="CodeCollapse"&gt;   &lt;pre style="margin: 0px"&gt;    &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: blue"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af"&gt;CompressionUtils&lt;/span&gt;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;    {&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;        &lt;span style="color: blue"&gt;const&lt;/span&gt; &lt;span style="color: blue"&gt;int&lt;/span&gt; BUFFERSIZE = 1024;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt; &lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;        &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: blue"&gt;byte&lt;/span&gt;[] Compress(&lt;span style="color: blue"&gt;byte&lt;/span&gt;[] data)&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;        {&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;            &lt;span style="color: blue"&gt;var&lt;/span&gt; memoryStream = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;MemoryStream&lt;/span&gt;();&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;            &lt;span style="color: blue"&gt;var&lt;/span&gt; deflateStream = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;DeflateStream&lt;/span&gt;(memoryStream, &lt;span style="color: #2b91af"&gt;CompressionMode&lt;/span&gt;.Compress);&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;            deflateStream.Write(data, 0, data.Length);&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;            deflateStream.Flush();&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;            deflateStream.Close();&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;            &lt;span style="color: blue"&gt;return&lt;/span&gt; memoryStream.ToArray();&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;        }&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt; &lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;        &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: blue"&gt;byte&lt;/span&gt;[] Decompress(&lt;span style="color: blue"&gt;byte&lt;/span&gt;[] data)&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;        {&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;            &lt;span style="color: blue"&gt;var&lt;/span&gt; buffer = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: blue"&gt;byte&lt;/span&gt;[BUFFERSIZE];&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;            &lt;span style="color: blue"&gt;var&lt;/span&gt; returnVal = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;byte&lt;/span&gt;&amp;gt;();&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt; &lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;            &lt;span style="color: blue"&gt;var&lt;/span&gt; deflateStream = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;DeflateStream&lt;/span&gt;(&lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;MemoryStream&lt;/span&gt;(data), &lt;span style="color: #2b91af"&gt;CompressionMode&lt;/span&gt;.Decompress);&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;            &lt;span style="color: blue"&gt;int&lt;/span&gt; count;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;            &lt;span style="color: blue"&gt;while&lt;/span&gt; ((count = deflateStream.Read(buffer, 0, BUFFERSIZE)) &amp;gt; 0)&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;            {&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;                &lt;span style="color: blue"&gt;if&lt;/span&gt; (count != BUFFERSIZE)&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;                {&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;                    &lt;span style="color: blue"&gt;var&lt;/span&gt; tmpBuffer = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: blue"&gt;byte&lt;/span&gt;[count];&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;                    &lt;span style="color: #2b91af"&gt;Array&lt;/span&gt;.Copy(buffer, tmpBuffer, count);&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;                    returnVal.AddRange(tmpBuffer);&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;                }&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;                &lt;span style="color: blue"&gt;else&lt;/span&gt;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;                    returnVal.AddRange(buffer);&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;            }&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt; &lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;            &lt;span style="color: blue"&gt;return&lt;/span&gt; returnVal.ToArray();&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;        }&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;    }&lt;/pre&gt;
&lt;/div&gt;&lt;img src="http://www.darkside.co.za/aggbug/112.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ryan Schreiber</dc:creator>
            <guid>http://www.darkside.co.za/archive/2010/05/11/compress-decompress-byte-array.aspx</guid>
            <pubDate>Tue, 11 May 2010 18:23:43 GMT</pubDate>
            <comments>http://www.darkside.co.za/archive/2010/05/11/compress-decompress-byte-array.aspx#feedback</comments>
            <wfw:commentRss>http://www.darkside.co.za/comments/commentRss/112.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Visual Studio 2010 &amp;ndash; Changing the theme</title>
            <link>http://www.darkside.co.za/archive/2010/04/13/changing-theme-visual-studio-2010.aspx</link>
            <description>&lt;p&gt;It’s been ages since I posted anything. The following code has had me tied up for the past few months :) :&lt;/p&gt;  &lt;p /&gt;  &lt;div class="Code"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="color: blue"&gt;this.&lt;/span&gt;&lt;span&gt;Children.Add(&lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;Child&lt;/span&gt;(&lt;span style="color: #a31515"&gt;"Sebastian"&lt;/span&gt;, &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;Date&lt;/span&gt;(2010, 1, 8));&lt;o:p /&gt;&lt;/span&gt;&lt;/p&gt; &lt;/div&gt;  &lt;p /&gt;  &lt;p&gt;Just to get going again, here’s a simple tip. I’ve just completed installing Visual Studio 2010, and the first thing that struck me was that there was still no way to change the theme. (And this mild OCD thing that I may or may not have means that everything must look the same and be neat). &lt;/p&gt;  &lt;p&gt;I found &lt;a title="Visual Studio Color Theme Editor" href="http://visualstudiogallery.msdn.microsoft.com/en-us/20cd93a2-c435-4d00-a797-499f16402378" target="_blank"&gt;this extension&lt;/a&gt; for VS2010 in the &lt;a title="Microsoft Visual Studio Gallery" href="http://visualstudiogallery.msdn.microsoft.com/en-us" target="_blank"&gt;Microsoft Visual Studio Gallery&lt;/a&gt;, and it works like a charm. When you initially install it, it adds a “Theme” menu to your IDE – after I set up the theme I needed, I simply customized the menu again to remove it.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.darkside.co.za/files/images/VisualStudio2010Changingthetheme_A57F/image.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.darkside.co.za/files/images/VisualStudio2010Changingthetheme_A57F/image_thumb.png" width="244" height="153" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Now my VS2010 IDE matches my Aero look and feel on my Windows 7 machine.&lt;/p&gt;&lt;img src="http://www.darkside.co.za/aggbug/111.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ryan Schreiber</dc:creator>
            <guid>http://www.darkside.co.za/archive/2010/04/13/changing-theme-visual-studio-2010.aspx</guid>
            <pubDate>Tue, 13 Apr 2010 09:46:40 GMT</pubDate>
            <comments>http://www.darkside.co.za/archive/2010/04/13/changing-theme-visual-studio-2010.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://www.darkside.co.za/comments/commentRss/111.aspx</wfw:commentRss>
        </item>
        <item>
            <title>A look at two card shuffling techniques</title>
            <link>http://www.darkside.co.za/archive/2009/11/12/two-card-shuffling-technique.aspx</link>
            <description>&lt;p&gt;I was asked by a colleague about how I might go about shuffling a deck of cards in C#. I found a few takes on this general problem on Google, and make no mistake: this has been covered by numerous persons over the last 80 years according to some of the research I found. So, yes, this is mostly likely a &lt;a href="http://en.wikipedia.org/wiki/Reinventing_the_wheel" target="_blank"&gt;Wheel Version 2.0&lt;/a&gt; piece of code, but here it is and hopefully it’ll be useful to someone.&lt;/p&gt;  &lt;p&gt;Firstly, you need to decide on a Random Number Generator. If you’re just interested in solving this card-shuffling problem as part of a hobby-type application, using the System.Random class provided, or in my case the System.Security.Cryptography.RandomNumberGenerator, will suffice. To make this really strong, you may want to look at a pseudo-random algorithm along the lines of the &lt;a href="en.wikipedia.org/wiki/Mersenne_twister" target="_blank"&gt;Mersenne twister&lt;/a&gt; or one of it’s improved variants, or the simpler to implement &lt;a href="http://en.wikipedia.org/wiki/Multiply-with-carry" target="_blank"&gt;Multiply-with-carry&lt;/a&gt;. Random number generators are really a topic all on their own and way out of the scope of this post.&lt;/p&gt;  &lt;p&gt;Now, onto the relatively simple part: Shuffling a 52 card deck. I’ve designed a simple Deck class to make it easier for displaying results, but the algorithms can easily be transferred to whatever structure you’re using to store your cards/deck. I’ve also added my RNG as a static local variable to the class to increase its effectiveness. (Also, part of the RNG-related topic)&lt;/p&gt;  &lt;div class="CodeCollapse"&gt;   &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af"&gt;Deck&lt;/span&gt; : &lt;span style="color: #2b91af"&gt;IEnumerable&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Deck&lt;/span&gt;.&lt;span style="color: #2b91af"&gt;SuitCard&lt;/span&gt;&amp;gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;{&lt;/p&gt;    &lt;p style="margin: 0px"&gt;    &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;enum&lt;/span&gt; &lt;span style="color: #2b91af"&gt;Suit&lt;/span&gt; { Spade, Diamond, Club, Heart }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;    &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;enum&lt;/span&gt; &lt;span style="color: #2b91af"&gt;Card&lt;/span&gt; { A, N2, N3, N4, N5, N6, N7, N8, N9, N10, J, Q, K }&lt;/p&gt;    &lt;p style="margin: 0px"&gt; &lt;/p&gt;    &lt;p style="margin: 0px"&gt;    &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af"&gt;SuitCard&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;    {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;long&lt;/span&gt; Index { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: #2b91af"&gt;Card&lt;/span&gt; Card { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: #2b91af"&gt;Suit&lt;/span&gt; Suit { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt; &lt;/p&gt;    &lt;p style="margin: 0px"&gt;        &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;override&lt;/span&gt; &lt;span style="color: blue"&gt;string&lt;/span&gt; ToString()&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            &lt;span style="color: blue"&gt;return&lt;/span&gt; Card.ToString().Replace(&lt;span style="color: #a31515"&gt;"N"&lt;/span&gt;, &lt;span style="color: #a31515"&gt;""&lt;/span&gt;) + &lt;span style="color: #a31515"&gt;" "&lt;/span&gt; + Suit;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;    }&lt;/p&gt;    &lt;p style="margin: 0px"&gt; &lt;/p&gt;    &lt;p style="margin: 0px"&gt;    &lt;span style="color: blue"&gt;private&lt;/span&gt; &lt;span style="color: blue"&gt;readonly&lt;/span&gt; &lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;SuitCard&lt;/span&gt;&amp;gt; m_List = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;SuitCard&lt;/span&gt;&amp;gt;();&lt;/p&gt;    &lt;p style="margin: 0px"&gt;    &lt;span style="color: blue"&gt;private&lt;/span&gt; &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: blue"&gt;readonly&lt;/span&gt; &lt;span style="color: #2b91af"&gt;RandomNumberGenerator&lt;/span&gt; m_Random = &lt;span style="color: #2b91af"&gt;RandomNumberGenerator&lt;/span&gt;.Create(); &lt;/p&gt;    &lt;p style="margin: 0px"&gt; &lt;/p&gt;    &lt;p style="margin: 0px"&gt;    &lt;span style="color: blue"&gt;public&lt;/span&gt; Deck () &lt;/p&gt;    &lt;p style="margin: 0px"&gt;    {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        &lt;span style="color: blue"&gt;int&lt;/span&gt; i = 0;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        &lt;span style="color: blue"&gt;foreach&lt;/span&gt; (&lt;span style="color: #2b91af"&gt;Suit&lt;/span&gt; suit &lt;span style="color: blue"&gt;in&lt;/span&gt; &lt;span style="color: #2b91af"&gt;Enum&lt;/span&gt;.GetValues(&lt;span style="color: blue"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;Suit&lt;/span&gt;)))&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            &lt;span style="color: blue"&gt;foreach&lt;/span&gt; (&lt;span style="color: #2b91af"&gt;Card&lt;/span&gt; card &lt;span style="color: blue"&gt;in&lt;/span&gt; &lt;span style="color: #2b91af"&gt;Enum&lt;/span&gt;.GetValues(&lt;span style="color: blue"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;Card&lt;/span&gt;)))&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            {&lt;/p&gt;    &lt;p style="margin: 0px"&gt; &lt;/p&gt;    &lt;p style="margin: 0px"&gt;                m_List.Add(&lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;SuitCard&lt;/span&gt;() { Card = card, Suit = suit, Index=i++ });&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;    }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;}&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;The first shuffle I’ve implemented is based on the &lt;a href="http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle" target="_blank"&gt;Knuth-Fisher-Yates&lt;/a&gt; shuffle and as you can see by the code, is amazingly simple to implement. &lt;/p&gt;  &lt;div class="CodeCollapse"&gt;   &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;    1&lt;/span&gt; &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; Shuffle()&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;    2&lt;/span&gt; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;    3&lt;/span&gt;     &lt;span style="color: green"&gt;//Knuth-Fisher-Yates shuffle algorithm&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;    4&lt;/span&gt;     &lt;span style="color: blue"&gt;for&lt;/span&gt; (&lt;span style="color: blue"&gt;int&lt;/span&gt; i = m_List.Count - 1; i &amp;gt; 0; i--)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;    5&lt;/span&gt;     {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;    6&lt;/span&gt;         &lt;span style="color: blue"&gt;var&lt;/span&gt; data = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: blue"&gt;byte&lt;/span&gt;[1];&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;    7&lt;/span&gt;         m_Random.GetBytes(data);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;    8&lt;/span&gt;         Swap(i, data[0] % (i + 1));&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;    9&lt;/span&gt;     }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   10&lt;/span&gt; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   11&lt;/span&gt; &lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   12&lt;/span&gt; &lt;span style="color: blue"&gt;private&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; Swap(&lt;span style="color: blue"&gt;int&lt;/span&gt; x, &lt;span style="color: blue"&gt;int&lt;/span&gt; y)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   13&lt;/span&gt; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   14&lt;/span&gt;     &lt;span style="color: #2b91af"&gt;Debug&lt;/span&gt;.Assert(x &amp;gt;= y); &lt;span style="color: green"&gt;//Just to make sure...&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   15&lt;/span&gt;     &lt;span style="color: #2b91af"&gt;SuitCard&lt;/span&gt; tmp = m_List[x];&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   16&lt;/span&gt;     m_List[x] = m_List[y];&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   17&lt;/span&gt;     m_List[y] = tmp;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   18&lt;/span&gt; }&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;Quoted from Wikipedia: The basic process of Fisher–Yates shuffling is similar to randomly picking numbered tickets out of a hat, or cards from a deck, one after another until there are no more left. What the specific algorithm provides is a way of doing this numerically in an efficient and rigorous manner that, properly done, guarantees an unbiased result. &lt;/p&gt;  &lt;p&gt;That being said, this computation as I’ve implemented in the source code is is prone to an effect known as &lt;a href="http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#Modulo_bias" target="_blank"&gt;modulo bias&lt;/a&gt; – you can seen the mod that is done on line 8.&lt;/p&gt;  &lt;p&gt;Another amazingly clever, yet simple, method of shuffling the cards is randomising a number, assigning it to the first card in the deck, and repeating the process for each card. Once you’ve completed, you order the cards by the random number, and your deck is shuffled.&lt;/p&gt;  &lt;div class="CodeCollapse"&gt;   &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   61&lt;/span&gt; &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; Shuffle()&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   62&lt;/span&gt; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   63&lt;/span&gt;     &lt;span style="color: blue"&gt;for&lt;/span&gt; (&lt;span style="color: blue"&gt;int&lt;/span&gt; i = 0; i &amp;lt; m_List.Count; i++)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   64&lt;/span&gt;     {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   65&lt;/span&gt;         &lt;span style="color: blue"&gt;var&lt;/span&gt; data = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: blue"&gt;byte&lt;/span&gt;[4];&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   66&lt;/span&gt;         m_Random.GetBytes(data);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   67&lt;/span&gt;         m_List[i].Index = data[0] + (data[1] * 256) + (data[2] * 65536) + (data[3] * 16777216);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   68&lt;/span&gt; &lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   69&lt;/span&gt;     }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   70&lt;/span&gt;     m_List.Sort(&lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;Comparison&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;SuitCard&lt;/span&gt;&amp;gt;(&lt;span style="color: blue"&gt;delegate&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;SuitCard&lt;/span&gt; x, &lt;span style="color: #2b91af"&gt;SuitCard&lt;/span&gt; y)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   71&lt;/span&gt;     {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   72&lt;/span&gt;         &lt;span style="color: blue"&gt;if&lt;/span&gt; (x.Index &amp;lt; y.Index) &lt;span style="color: blue"&gt;return&lt;/span&gt; (-1);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   73&lt;/span&gt;         &lt;span style="color: blue"&gt;if&lt;/span&gt; (x.Index &amp;gt; y.Index) &lt;span style="color: blue"&gt;return&lt;/span&gt; (1);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   74&lt;/span&gt;         &lt;span style="color: blue"&gt;return&lt;/span&gt; 0;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   75&lt;/span&gt;     }));&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   76&lt;/span&gt; }&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;I use the same RNG, and then convert the four bytes to a long (line 67) – this is the field that I “sort” the deck by, to give you a shuffled deck.&lt;/p&gt;  &lt;p&gt;And that’s my two ways of shuffling a deck of cards in C#.&lt;/p&gt;&lt;img src="http://www.darkside.co.za/aggbug/108.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ryan Schreiber</dc:creator>
            <guid>http://www.darkside.co.za/archive/2009/11/12/two-card-shuffling-technique.aspx</guid>
            <pubDate>Thu, 12 Nov 2009 08:37:45 GMT</pubDate>
            <comments>http://www.darkside.co.za/archive/2009/11/12/two-card-shuffling-technique.aspx#feedback</comments>
            <wfw:commentRss>http://www.darkside.co.za/comments/commentRss/108.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Table designer in SQL 2008 Management Studio prevents saving table changes</title>
            <link>http://www.darkside.co.za/archive/2009/10/08/table-designer-sql-2008-saving-tables.aspx</link>
            <description>&lt;p&gt;If you get an error message along the lines of “Saving changes is not permitted. The changes you have made…”, it’s actually an option that can be toggled. Go to Tools-&amp;gt;Options-&amp;gt;Designers-&amp;gt;Table and Database Designers and toggle the “Prevent saving changes..” option.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.darkside.co.za/files/images/TabledesignerinSQL2008ManagementStudiopr_A0A1/image.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.darkside.co.za/files/images/TabledesignerinSQL2008ManagementStudiopr_A0A1/image_thumb.png" width="595" height="344" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://www.darkside.co.za/aggbug/107.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ryan Schreiber</dc:creator>
            <guid>http://www.darkside.co.za/archive/2009/10/08/table-designer-sql-2008-saving-tables.aspx</guid>
            <pubDate>Thu, 08 Oct 2009 09:25:09 GMT</pubDate>
            <comments>http://www.darkside.co.za/archive/2009/10/08/table-designer-sql-2008-saving-tables.aspx#feedback</comments>
            <wfw:commentRss>http://www.darkside.co.za/comments/commentRss/107.aspx</wfw:commentRss>
        </item>
        <item>
            <title>candidate.IsSenior != candidate.CanCodeGood</title>
            <link>http://www.darkside.co.za/archive/2009/07/31/senior-developer-not-equal-good-developer.aspx</link>
            <description>&lt;p&gt;Rant()&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;Stop reading here if you’re looking for something technical :) &lt;/p&gt;  &lt;p&gt;I’ve recently started interviewing candidates for what I would describe as a mid-level developer, skilled in ASP.Net/C#. This brought back memories of much the same exercise I went through last year when looking for a med-to-senior level developer. &lt;/p&gt;  &lt;p&gt;So to summarise how I think that went, I’ll paraphrase some questions and answers that have stuck with me:&lt;/p&gt;  &lt;p&gt;Q: Does C# support multiple inheritance?    &lt;br /&gt;A: I’ve never really needed to use inheritance, so I haven’t paid much attention to it.&lt;/p&gt;  &lt;p&gt;Q: Can you explain the concept of generics and what they add to C#?    &lt;br /&gt;A: C# allows you to program almost anything and that makes it quite generic.&lt;/p&gt;  &lt;p&gt;Q: Can you explain to me what an abstract class is?    &lt;br /&gt;A: An abstract class is like a class but it isn't really one. It can't do anything.&lt;/p&gt;  &lt;p&gt;Dismal. I have a wild imagination, and when I start thinking back to this, my mind is filled with the imaginative sound of a downward-spiral-type-thing. It's a lot like in the Road Runner cartoon when Wile E Coyote falls of the cliff, except in a spiral, going back and forth from ear to ear.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.darkside.co.za/files/images/SeniorDevelopervsSeniorDeveloper_C78D/WileECoyote.jpg"&gt;&lt;img title="Wile-E-Coyote" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="142" alt="Wile-E-Coyote" src="http://www.darkside.co.za/files/images/SeniorDevelopervsSeniorDeveloper_C78D/WileECoyote_thumb.jpg" width="234" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;I digress.&lt;/p&gt;  &lt;p&gt;Before I get flamed with comments like “Aren’t these loaded/catch questions?” or “I’m sure you can find the answers on Google very quickly”, I have to ask a question: Surely these concepts should be understood by someone applying for a mid-level/senior developer position? What intrigued me at the time was the oft occurring idea that many of these candidates classed themselves as senior because they were either the person who had been at their previous company the longest, or they had managed to secure their current position which had that title.&lt;/p&gt;  &lt;p&gt;I feel that a senior developer should have excellent knowledge of the language he is working in; he should be able to work on almost any code or project unsupervised, and require very little input on “how to do things”. I found &lt;a title="What is your definition of a Entry Level/Junior/Mid/Senior Developer?" href="http://stackoverflow.com/questions/230171/what-is-your-definition-of-a-entry-leveljuniormidsenior-developer" target="_blank"&gt;this article on StackOverflow&lt;/a&gt; and the first answer (at the time of writing started with “We have similar gradings:”) is very much in line with my thinking and what I expect. I also think that a working knowledge of concepts like patterns, common algorithms, lazy loading and continuations are a plus. So, if I get a CV that describes the candidate as “senior developer”, I expect this person to be pretty damn good and they can expect me to give them an equally good grilling during the interview.&lt;/p&gt;  &lt;p&gt;My idea of mid-level developers is that they have reasonable knowledge about the language they’re working in, can handle small projects by themselves with some guidance from a senior, and should be able to write a string reverse function which does simple things like boundary checking, null reference checks, etc. The reason I include that last one is that it’s one of the questions I ask in the practical test for mid-level developers. As of today, the score is zero out of four.&lt;/p&gt;  &lt;p&gt;Maybe I’m expecting too much. &lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;&lt;img src="http://www.darkside.co.za/aggbug/103.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ryan Schreiber</dc:creator>
            <guid>http://www.darkside.co.za/archive/2009/07/31/senior-developer-not-equal-good-developer.aspx</guid>
            <pubDate>Fri, 31 Jul 2009 13:56:31 GMT</pubDate>
            <comments>http://www.darkside.co.za/archive/2009/07/31/senior-developer-not-equal-good-developer.aspx#feedback</comments>
            <wfw:commentRss>http://www.darkside.co.za/comments/commentRss/103.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Who is to blame?</title>
            <link>http://www.darkside.co.za/archive/2009/03/10/who-is-to-blame.aspx</link>
            <description>&lt;p&gt;Here's a portion of a screen shot I took earlier yesterday evening:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.darkside.co.za/files/images/Snafu001.jpg"&gt;&lt;img style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height="221" alt="Snafu" width="244" border="0" src="http://www.darkside.co.za/files/images/Snafu001_thumb.jpg" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;The portion I've highlighted must surely have been a copy-and-paste mistake, as it's totally out of context. More to the point, shouldn't this should have been:&lt;/p&gt;
&lt;p&gt;(a) proof read by the author&lt;/p&gt;
&lt;p&gt;(b) proof read by an editor&lt;/p&gt;
&lt;p&gt;They can argue about who's fault it is :)&lt;/p&gt;
&lt;p&gt;This started me thinking (again) about issues like this in my line of work. Make no mistake - back in software development land we also have snafu's that slip out into production - like a message box displaying debug information that wasn't commented out before a build.&lt;/p&gt;
&lt;p&gt;If found out in the wild, the blame-game starts in all earnest and will inevitably lead to a developer saying "That's not my fault. QA okayed it to be released" with the rebuttal on many an occasion being "We can't test every little change you do, only portions that we thought were important/had time to test/etc". &lt;/p&gt;
&lt;p&gt;I have two conflicting thoughts about this type of scenario. The first is that it's the developers fault. I feel that this is just plain sloppy on his or her part (or mine, for that matter) and shouldn't have been left in production code.&lt;/p&gt;
&lt;p&gt;My second thought is that it's QA's fault. QA has the final say. They should have tested the software properly and they ultimately had the say as to whether it was OK to be let out into the wild.&lt;/p&gt;
&lt;p&gt;So where does that leave me? Well, actually, the conflict in my head getting less, and is only because I'm fighting the instinct to blame someone else. &lt;a href="http://www.codinghorror.com/blog/archives/001079.html"&gt;Jeff Atwood wrote an article&lt;/a&gt; about where the responsibility lies, and I'm trying to take this stance in my work. I am aware now, through a lot of personal habit changing exercises, that I'm responsible for the code I wrote and that eating humble pie on the odd occasion is something I have to do to become a better programmer&lt;/p&gt;&lt;img src="http://www.darkside.co.za/aggbug/95.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ryan Schreiber</dc:creator>
            <guid>http://www.darkside.co.za/archive/2009/03/10/who-is-to-blame.aspx</guid>
            <pubDate>Tue, 10 Mar 2009 03:45:17 GMT</pubDate>
            <comments>http://www.darkside.co.za/archive/2009/03/10/who-is-to-blame.aspx#feedback</comments>
            <wfw:commentRss>http://www.darkside.co.za/comments/commentRss/95.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Windows Media Player &amp;ndash; File name format</title>
            <link>http://www.darkside.co.za/archive/2009/03/02/windows-media-player-file-name-format.aspx</link>
            <description>&lt;p&gt;This is a mini-rant about usability, with a workaround – so excuse me if this isn’t quite in the same vane as my usual posts. &lt;/p&gt;  &lt;p&gt;I’m pretty sticky about how my file names should be formatted when WMP rips a CD, my preference being:&lt;/p&gt;  &lt;p&gt;Track Number – Artist – Album – Song Title.ext &lt;/p&gt;  &lt;p&gt;WMP gives you the option of selecting/arranging fields in any number of ways, and gives you some predefined options for the separator. One of them is the dash, which I have selected, and then I use my trusty &lt;a href="http://www.ghisler.com/" target="_blank"&gt;Total Commander&lt;/a&gt; to do mass renaming after the fact. &lt;/p&gt;  &lt;p&gt;I just took it for granted that these options were hard-coded into the app, until I noticed that my Media Centre PC would rename files based on my settings in WMP when I was fiddling around with different options, praying that the latest updates had given me some new options :). I popped open &lt;a title="RegMon" href="http://technet.microsoft.com/en-us/sysinternals/bb896652.aspx" target="_blank"&gt;RegMon&lt;/a&gt; to get an idea of where these settings were being save, fiddled some more with the settings in WMP, and then into the registry I went while hoping that the separator wasn’t just being stored as an index. Lo and behold, it’s a string. &lt;/p&gt;  &lt;p&gt;There is a key called “CDRecordFileSeparator”, which is a REG_SZ (string)in HKCU\Software\Microsoft\MediaPlayer\Preferences. Change it, and the result is seen immediately in WMP.&lt;/p&gt;  &lt;p&gt;Now, I have to ask: Surely they could have had an option called “Custom” which allows you to put in your own separator? It must’ve come up during someone’s tests! End of mini-rant.&lt;/p&gt;  &lt;p&gt;If you do decide to use your own custom setting - take note that if you go back into the Rip settings tab in media player the drop-down is set to (None) and if you apply any new settings your custom separator is overwritten.&lt;/p&gt;&lt;img src="http://www.darkside.co.za/aggbug/94.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ryan Schreiber</dc:creator>
            <guid>http://www.darkside.co.za/archive/2009/03/02/windows-media-player-file-name-format.aspx</guid>
            <pubDate>Mon, 02 Mar 2009 04:00:00 GMT</pubDate>
            <comments>http://www.darkside.co.za/archive/2009/03/02/windows-media-player-file-name-format.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://www.darkside.co.za/comments/commentRss/94.aspx</wfw:commentRss>
        </item>
        <item>
            <title>GeneratorStudio and project/file layouts</title>
            <link>http://www.darkside.co.za/archive/2009/02/15/generator-studio-project-file-layouts.aspx</link>
            <description>&lt;p&gt;This is just a tip for anyone using &lt;a href="http://www.codeplex.com/generatorstudio"&gt;GeneratorStudio&lt;/a&gt; or any other code generator for their ActiveRecord classes (or any other classes, for that matter). &lt;/p&gt; &lt;p&gt;I generally have my templates set up to generate my files with the name "&amp;lt;TABLENAME&amp;gt;.Generated.cs" or something similar. In addition to this naming convention, I also make sure that my generated classes are marked as partial classes, and then I do all custom code, like additional "Find" methods methods, etc, in files named "&amp;lt;TABLENAME&amp;gt;.cs". &lt;/p&gt; &lt;p&gt;This way, when you need to regenerate anything, you can be comfortable with overwriting all the classes that are "&amp;lt;TABLENAME&amp;gt;.Generated.cs" without worrying about overwriting code that you don't want to lose.&lt;/p&gt; &lt;p&gt;You can go one step further and drop the generated files in their own folder - I name my "Generated", and I change the property named "Namespace Provider" on the folder to false.&lt;/p&gt;&lt;img src="http://www.darkside.co.za/aggbug/93.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ryan Schreiber</dc:creator>
            <guid>http://www.darkside.co.za/archive/2009/02/15/generator-studio-project-file-layouts.aspx</guid>
            <pubDate>Sun, 15 Feb 2009 17:28:42 GMT</pubDate>
            <comments>http://www.darkside.co.za/archive/2009/02/15/generator-studio-project-file-layouts.aspx#feedback</comments>
            <wfw:commentRss>http://www.darkside.co.za/comments/commentRss/93.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Generator Studio released on CodePlex</title>
            <link>http://www.darkside.co.za/archive/2008/10/30/generator-studio-released-on-codeplex.aspx</link>
            <description>&lt;p&gt;Generator Studio is a code generation tool (yes, another one one, but more on that later) that allows you to set up templates using the Velocity Template Language, and then generates files based on your source database structure. It can be found &lt;a href="http://www.codeplex.com/generatorstudio"&gt;here on CodePlex&lt;/a&gt; and the Pre-Beta 0.1 can be &lt;a href="http://www.codeplex.com/generatorstudio/Release/ProjectReleases.aspx?ReleaseId=18896"&gt;downloaded here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;WARNING: It's very beta. Its generates well (we think), but we have a host of features/fixes that we'd like to add in the future. At present, it's being contributed to by FryHard (a.k.a. Brendan Fry) and I, and we tackle it in our spare time.Top of our list is to tidy up the UI side, and implement ALL of the sql calls using NHibernate/ActiveRecord. You may notice some inline SQL statements that, at present, I haven't managed to work around (mostly because of time constraints :)).&lt;/p&gt;
&lt;p&gt;Why another generator application? I agree fully with the thoughts around the "&lt;a href="http://en.wikipedia.org/wiki/Reinventing_the_wheel"&gt;Reinventing-the-wheel&lt;/a&gt;" anti-pattern - developing something that is already out there, but you don't like it because you didn't write it, is stoopid. &lt;strong&gt;BUT&lt;/strong&gt;. I started this many years back in some-or-other form, and in recent times I've struggled to find an open-source project the generates what I want. So here it is.&lt;/p&gt;
&lt;p&gt;Use it. Don't use it. Send us templates. Check back here/codeplex to find new templates.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;UPDATE: 2008 NOV 03 &lt;/strong&gt;4 extra templates have been added to the source - 2 for creating audit tables for your database (one style using a GUID as the PK for the audit tables, the other using an identity column) and the other two for generating the corresponding triggers to populate these tables. &lt;/p&gt;&lt;img src="http://www.darkside.co.za/aggbug/61.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ryan Schreiber</dc:creator>
            <guid>http://www.darkside.co.za/archive/2008/10/30/generator-studio-released-on-codeplex.aspx</guid>
            <pubDate>Thu, 30 Oct 2008 05:47:39 GMT</pubDate>
            <comments>http://www.darkside.co.za/archive/2008/10/30/generator-studio-released-on-codeplex.aspx#feedback</comments>
            <wfw:commentRss>http://www.darkside.co.za/comments/commentRss/61.aspx</wfw:commentRss>
            <enclosure url="http://www.codeplex.com/generatorstudio/Release/ProjectReleases.aspx?ReleaseId=18896" length="1257472" type="application/octetstream" />
        </item>
        <item>
            <title>Use "runas" to test Windows Authentication</title>
            <link>http://www.darkside.co.za/archive/2008/05/12/use-runas-to-test-windows-authentication.aspx</link>
            <description>&lt;p&gt;I've recently needed to test an app on Windows XP that makes use of Windows Authentication for the application as well as for the Sql connection string, with different application functionality assigned to Windows users, and the various permissions that are set in Sql. Short of having to log in and out with every different user (which wasn't going to happen), I wasn't sure how this was going to happen, until I remembered the "runsas" DOS command. &lt;/p&gt;
&lt;p&gt;Simply put, you can enter the following:&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;C:\&amp;gt;RUNAS.EXE /USER:&amp;lt;UserYouWantToRunAs&amp;gt; &amp;lt;ApplicationToRun&amp;gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;On a few occasions I needed to debug some of the code, running as a specific user. I found two ways to do this, the first is to run Visual Studio as this user , the other is to add to you entry point of your app (and maybe put #if DEBUG #endif around this)&lt;/p&gt;
&lt;div class="Code"&gt;
&lt;pre style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (!System.Diagnostics.&lt;span style="COLOR: #2b91af"&gt;Debugger&lt;/span&gt;.IsAttached)&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;    System.Diagnostics.&lt;span style="COLOR: #2b91af"&gt;Debugger&lt;/span&gt;.Launch();&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This starts your configured debugger (or gives you a choice of which debugger to use) and is immediately attached.&lt;!--EndFragment--&gt;&lt;/p&gt;&lt;img src="http://www.darkside.co.za/aggbug/36.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Darksider</dc:creator>
            <guid>http://www.darkside.co.za/archive/2008/05/12/use-runas-to-test-windows-authentication.aspx</guid>
            <pubDate>Mon, 12 May 2008 06:58:28 GMT</pubDate>
            <comments>http://www.darkside.co.za/archive/2008/05/12/use-runas-to-test-windows-authentication.aspx#feedback</comments>
            <wfw:commentRss>http://www.darkside.co.za/comments/commentRss/36.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>