<?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:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>ProgramGood.Net - c# language</title>
    <link>http://www.programgood.net/</link>
    <description>The journey to becoming a great programmer</description>
    <language>en-us</language>
    <copyright>Dave Mateer</copyright>
    <lastBuildDate>Sat, 19 May 2012 20:20:34 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.2.8279.16125</generator>
    <managingEditor>davemateer@gmail.com</managingEditor>
    <webMaster>davemateer@gmail.com</webMaster>
    <item>
      <trackback:ping>http://www.programgood.net/Trackback.aspx?guid=616d76f6-b63e-4e7e-b95d-313a442b6665</trackback:ping>
      <pingback:server>http://www.programgood.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.programgood.net/PermaLink,guid,616d76f6-b63e-4e7e-b95d-313a442b6665.aspx</pingback:target>
      <dc:creator>Dave Mateer</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Supposed to be the introduction episode <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://www.programgood.net/content/binary/Windows-Live-Writer/29d7293f30dc_C366/wlEmoticon-smile_2.png" /></p>
        <h2>Dynamic
</h2>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:64f7a965-b356-44e1-b6dd-c29f8606726b" class="wlWriterEditableSmartContent">
          <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
            <div style="background-color: #ffffff; max-height: 400px; overflow: auto; padding: 2px 5px;">
              <span style="color:#0000ff">static</span>
              <span style="color:#0000ff">void</span> Main(<span style="color:#0000ff">string</span>[]
args)<br />
{<br /><span style="color:#0000ff">object</span> x = <span style="color:#0000ff">new</span><span style="color:#2b91af">List</span>&lt;<span style="color:#0000ff">int</span>&gt;();<br /><span style="color:#008000">//will give an InvalidCastException at runtime</span><br /><span style="color:#0000ff">string</span> y = (<span style="color:#0000ff">string</span>)
x;<br /><span style="color:#2b91af">Console</span>.WriteLine(y.Length);<br />
}
</div>
          </div>
        </div>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:f5a82609-b590-4871-b2eb-6f439f6fa5cd" class="wlWriterEditableSmartContent">
          <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
            <div style="background-color: #ffffff; max-height: 500px; overflow: auto; padding: 2px 5px;">
              <span style="color:#0000ff">object</span> x
= <span style="color:#a31515">"hello"</span>;<br /><span style="color:#0000ff">string</span> y = (<span style="color:#0000ff">string</span>)
x;<br /><span style="color:#2b91af">Console</span>.WriteLine(y.Length);
</div>
          </div>
        </div>
        <p>
gives answer of 5
</p>
        <p>
        </p>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:d154d44a-01fe-4346-ad33-cddfe410c9ca" class="wlWriterEditableSmartContent">
          <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
            <div style="background-color: #ffffff; max-height: 400px; overflow: auto; padding: 2px 5px;">
              <span style="color:#0000ff">object</span> x
= <span style="color:#0000ff">null</span>;<br /><span style="color:#008000">//we can cast a null reference</span><br /><span style="color:#0000ff">string</span> y = (<span style="color:#0000ff">string</span>)x;<br /><span style="color:#008000">//but we cant dereference it..get a nullReferenceException</span><br /><span style="color:#2b91af">Console</span>.WriteLine(y.Length);
</div>
          </div>
        </div>
        <p>
sdf
</p>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:ccf3e83e-09cb-4b0a-8a97-5c9a0cbfccdc" class="wlWriterEditableSmartContent">
          <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
            <div style="background-color: #ffffff; max-height: 400px; overflow: auto; padding: 2px 5px;">
              <span style="color:#008000">//don't
think of x at any type... sort out at execution time</span>
              <br />
              <span style="color:#0000ff">dynamic</span> x = <span style="color:#a31515">"hello"</span>;<br /><span style="color:#008000">//5</span><br /><span style="color:#2b91af">Console</span>.WriteLine(x.Length);<br /><br /><span style="color:#008000">//an array</span><br />
x = <span style="color:#0000ff">new</span><span style="color:#0000ff">int</span>[]
{10, 20, 30 };<br /><span style="color:#008000">//3</span><br /><span style="color:#2b91af">Console</span>.WriteLine(x.Length);
</div>
          </div>
        </div>
        <p>
from
</p>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:5191df73-7849-4858-91dd-2f91cf754dfd" class="wlWriterEditableSmartContent">
          <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
            <div style="background-color: #ffffff; max-height: 400px; overflow: auto; padding: 2px 5px;">
              <span style="color:#0000ff">int</span> x
= 123;<br /><span style="color:#0000ff">int</span> y = 10;<br /><span style="color:#2b91af">Console</span>.WriteLine(x-y);
</div>
          </div>
        </div>
        <p>
          <a href="http://www.programgood.net/content/binary/Windows-Live-Writer/29d7293f30dc_C366/image_2.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/Windows-Live-Writer/29d7293f30dc_C366/image_thumb.png" width="533" height="512" />
          </a>
        </p>
        <p>
using ildasm to disassemble the debug assembly.  The nop statements are for debug.
</p>
        <p>
This is op code (IL).. i4 is like int32
</p>
        <p>
load 123 and put into stack position 0
</p>
        <p>
load 10 and put into stack position 1
</p>
        <p>
then put into dynamic types
</p>
        <h2>Named Arguments
</h2>
        <p>
Whats an argument and whats a parameter?
</p>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:b4dac9ec-2f0d-4d1b-b1b9-c8e423a803dc" class="wlWriterEditableSmartContent">
          <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
            <div style="background-color: #ffffff; max-height: 400px; overflow: auto; padding: 2px 5px;">
              <span style="color:#0000ff">static</span>
              <span style="color:#0000ff">void</span> Main(<span style="color:#0000ff">string</span>[]
args)<br />
{<br /><span style="color:#008000">//provide an argument</span><br />
Foo(<span style="color:#a31515">"hello"</span>);<br />
}<br /><br /><span style="color:#008000">//x is a parameter</span><br /><span style="color:#0000ff">static</span><span style="color:#0000ff">void</span> Foo(<span style="color:#0000ff">string</span> x)<br />
{<br /><span style="color:#2b91af">Console</span>.WriteLine(x);<br />
}<br />
}
</div>
          </div>
        </div>
        <p>
          <a href="http://www.programgood.net/content/binary/Windows-Live-Writer/29d7293f30dc_C366/image_4.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/Windows-Live-Writer/29d7293f30dc_C366/image_thumb_1.png" width="270" height="353" />
          </a>
        </p>
        <p>
Got it the wrong way round.. hard to tell which is which in MessageBox.Show
</p>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:23b168ab-1590-4db7-8367-b86e9c979516" class="wlWriterEditableSmartContent">
          <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
            <div style="background-color: #ffffff; max-height: 400px; overflow: auto; padding: 2px 5px;">
              <span style="color:#0000ff">static</span>
              <span style="color:#0000ff">void</span> Main(<span style="color:#0000ff">string</span>[]
args)<br />
{<br /><span style="color:#008000">//named argument C#4</span><br />
Foo(x: <span style="color:#a31515">"hello"</span>, y:<span style="color:#a31515">"Rob"</span>);<br /><span style="color:#008000">//referenced System.Windows.Forms</span><br /><span style="color:#2b91af">MessageBox</span>.Show(caption:<span style="color:#a31515">"title"</span>,
text:<span style="color:#a31515">"body"</span>);<br />
}<br /><br /><span style="color:#008000">//x is a parameter</span><br /><span style="color:#0000ff">static</span><span style="color:#0000ff">void</span> Foo(<span style="color:#0000ff">string</span> x, <span style="color:#0000ff">string</span> y)<br />
{<br /><span style="color:#2b91af">Console</span>.WriteLine(x + <span style="color:#a31515">"
"</span> + y);<br />
}
</div>
          </div>
        </div>
        <p>
better!
</p>
        <h2>Optional Parameters
</h2>
        <p>
        </p>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:af2b379f-46a9-43a6-bd15-e8c4cdb74cdc" class="wlWriterEditableSmartContent">
          <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
            <div style="background-color: #ffffff; max-height: 400px; overflow: auto; padding: 2px 5px;">
              <span style="color:#0000ff">static</span>
              <span style="color:#0000ff">void</span> Main(<span style="color:#0000ff">string</span>[]
args)<br />
{<br /><span style="color:#008000">//named arguments</span><br />
Foo(y: <span style="color:#a31515">"Rob"</span>);<br />
Foo(y: <span style="color:#a31515">"Dave"</span>);<br />
Foo(y: <span style="color:#a31515">"Mike"</span>);<br />
Foo(y: <span style="color:#a31515">"Bill"</span>);<br />
Foo(<span style="color:#a31515">"Hi"</span>, <span style="color:#a31515">"Anders"</span>);<br />
Foo();<br />
}<br /><br /><span style="color:#008000">//optional parameters</span><br /><span style="color:#008000">//if first parameter is optional all have to be</span><br /><span style="color:#0000ff">static</span><span style="color:#0000ff">void</span> Foo(<span style="color:#0000ff">string</span> x
= <span style="color:#a31515">"Hello"</span>, <span style="color:#0000ff">string</span> y
= <span style="color:#a31515">"Everone"</span>)<br />
{ 
<br /><span style="color:#2b91af">Console</span>.WriteLine(x + <span style="color:#a31515">"
"</span> + y);<br />
}<br />
}
</div>
          </div>
        </div>
        <h2>Covariance and Contravariance
</h2>
        <p>
Some code here.. poster child of the more used covariance is IEnumerable&lt;T&gt;..
look for out keword.  And it is to do with hierarchies.
</p>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e1a928d3-bffc-47df-b173-ef3b54e9eceb" class="wlWriterEditableSmartContent">
          <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
            <div style="background-color: #ffffff; max-height: 400px; overflow: auto; padding: 2px 5px;">
              <span style="color:#0000ff">class</span>
              <span style="color:#2b91af">Fruit</span> {
}<br /><span style="color:#0000ff">class</span><span style="color:#2b91af">Banana</span> : <span style="color:#2b91af">Fruit</span> {
}<br /><span style="color:#0000ff">class</span><span style="color:#2b91af">Apple</span> : <span style="color:#2b91af">Fruit</span> {
}<br /><br /><span style="color:#008000">//interface IEnumerable&lt;out T&gt;</span><br /><span style="color:#008000">//{</span><br /><span style="color:#008000">// IEnumerator&lt;T&gt; GetEnumerator();</span><br /><span style="color:#008000">//}</span><br /><br /><span style="color:#008000">//interface IEnumerator&lt;out T&gt; : IDisposable</span><br /><span style="color:#008000">//{</span><br /><span style="color:#008000">// T Current { get; }</span><br /><span style="color:#008000">// bool MoveNext();</span><br /><span style="color:#008000">// void Reset();</span><br /><span style="color:#008000">//}</span><br /><br /><span style="color:#008000">//covariance values coming out of an interface</span><br /><span style="color:#008000">//usually happens with IEnumerable of T</span><br /><span style="color:#0000ff">interface</span><span style="color:#2b91af">IFoo</span>&lt;<span style="color:#0000ff">out</span> T&gt;<br />
{<br />
T GiveMeAnInstanceOfT();<br /><span style="color:#008000">//void TakeanInstanceOfT(T instance);</span><br />
}<br /><br /><span style="color:#008000">//contravariance is in</span><br /><br /><span style="color:#0000ff">class</span><span style="color:#2b91af">Program</span><br />
{<br /><span style="color:#0000ff">static</span><span style="color:#0000ff">void</span> Main(<span style="color:#0000ff">string</span>[]
args)<br />
{<br /><span style="color:#008000">//List&lt;Banana&gt; bunchOfBananas = new List&lt;Banana&gt;();</span><br /><span style="color:#2b91af">IFoo</span>&lt;<span style="color:#2b91af">Banana</span>&gt;
bunchOfBananas = <span style="color:#0000ff">null</span>;<br /><br /><span style="color:#008000">//cant convert from a list of banana to a list of fruit</span><br /><span style="color:#008000">//List&lt;Fruit&gt; fruitBowl = new List&lt;Banana&gt;();</span><br /><br /><span style="color:#008000">//List&lt;Fruit&gt; fruitBowl = bunchOfBananas;</span><br /><span style="color:#008000">//fruitBowl.Add(new Apple());</span><br /><br /><span style="color:#008000">//Banana banana = bunchOfBananas[0]; </span><br /><br /><span style="color:#008000">//IEnumerable - sequence..cant add.. can only observe</span><br /><span style="color:#008000">//IEnumerable&lt;Fruit&gt; fruitBowl = bunchOfBananas;</span><br /><span style="color:#2b91af">IFoo</span>&lt;<span style="color:#2b91af">Fruit</span>&gt;
fruitBowl = bunchOfBananas;<br />
}<br />
}
</div>
          </div>
        </div>
        <img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=616d76f6-b63e-4e7e-b95d-313a442b6665" />
      </body>
      <title>TekPub C#4 Jon Skeet</title>
      <guid isPermaLink="false">http://www.programgood.net/PermaLink,guid,616d76f6-b63e-4e7e-b95d-313a442b6665.aspx</guid>
      <link>http://www.programgood.net/2012/05/19/TekPubC4JonSkeet.aspx</link>
      <pubDate>Sat, 19 May 2012 20:20:34 GMT</pubDate>
      <description>&lt;p&gt;
Supposed to be the introduction episode &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://www.programgood.net/content/binary/Windows-Live-Writer/29d7293f30dc_C366/wlEmoticon-smile_2.png" /&gt;
&lt;/p&gt;
&lt;h2&gt;Dynamic
&lt;/h2&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:64f7a965-b356-44e1-b6dd-c29f8606726b" class="wlWriterEditableSmartContent"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt;
&lt;div style="background-color: #ffffff; max-height: 400px; overflow: auto; padding: 2px 5px;"&gt;&lt;span style="color:#0000ff"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; Main(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;[]
args)&lt;br&gt;
{&lt;br&gt;
&lt;span style="color:#0000ff"&gt;object&lt;/span&gt; x = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:#0000ff"&gt;int&lt;/span&gt;&amp;gt;();&lt;br&gt;
&lt;span style="color:#008000"&gt;//will give an InvalidCastException at runtime&lt;/span&gt;
&lt;br&gt;
&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; y = (&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;)
x;&lt;br&gt;
&lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(y.Length);&lt;br&gt;
}
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:f5a82609-b590-4871-b2eb-6f439f6fa5cd" class="wlWriterEditableSmartContent"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt;
&lt;div style="background-color: #ffffff; max-height: 500px; overflow: auto; padding: 2px 5px;"&gt;&lt;span style="color:#0000ff"&gt;object&lt;/span&gt; x
= &lt;span style="color:#a31515"&gt;&amp;quot;hello&amp;quot;&lt;/span&gt;;&lt;br&gt;
&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; y = (&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;)
x;&lt;br&gt;
&lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(y.Length);
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
gives answer of 5
&lt;/p&gt;
&lt;p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:d154d44a-01fe-4346-ad33-cddfe410c9ca" class="wlWriterEditableSmartContent"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt;
&lt;div style="background-color: #ffffff; max-height: 400px; overflow: auto; padding: 2px 5px;"&gt;&lt;span style="color:#0000ff"&gt;object&lt;/span&gt; x
= &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;;&lt;br&gt;
&lt;span style="color:#008000"&gt;//we can cast a null reference&lt;/span&gt;
&lt;br&gt;
&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; y = (&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;)x;&lt;br&gt;
&lt;span style="color:#008000"&gt;//but we cant dereference it..get a nullReferenceException&lt;/span&gt;
&lt;br&gt;
&lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(y.Length);
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&gt;
&lt;p&gt;
sdf
&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:ccf3e83e-09cb-4b0a-8a97-5c9a0cbfccdc" class="wlWriterEditableSmartContent"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt;
&lt;div style="background-color: #ffffff; max-height: 400px; overflow: auto; padding: 2px 5px;"&gt;&lt;span style="color:#008000"&gt;//don&amp;#39;t
think of x at any type... sort out at execution time&lt;/span&gt;
&lt;br&gt;
&lt;span style="color:#0000ff"&gt;dynamic&lt;/span&gt; x = &lt;span style="color:#a31515"&gt;&amp;quot;hello&amp;quot;&lt;/span&gt;;&lt;br&gt;
&lt;span style="color:#008000"&gt;//5&lt;/span&gt;
&lt;br&gt;
&lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(x.Length);&lt;br&gt;
&lt;br&gt;
&lt;span style="color:#008000"&gt;//an array&lt;/span&gt;
&lt;br&gt;
x = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#0000ff"&gt;int&lt;/span&gt;[]
{10, 20, 30 };&lt;br&gt;
&lt;span style="color:#008000"&gt;//3&lt;/span&gt;
&lt;br&gt;
&lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(x.Length);
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
from
&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:5191df73-7849-4858-91dd-2f91cf754dfd" class="wlWriterEditableSmartContent"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt;
&lt;div style="background-color: #ffffff; max-height: 400px; overflow: auto; padding: 2px 5px;"&gt;&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; x
= 123;&lt;br&gt;
&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; y = 10;&lt;br&gt;
&lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(x-y);
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/Windows-Live-Writer/29d7293f30dc_C366/image_2.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/Windows-Live-Writer/29d7293f30dc_C366/image_thumb.png" width="533" height="512" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
using ildasm to disassemble the debug assembly.&amp;#160; The nop statements are for debug.
&lt;/p&gt;
&lt;p&gt;
This is op code (IL).. i4 is like int32
&lt;/p&gt;
&lt;p&gt;
load 123 and put into stack position 0
&lt;/p&gt;
&lt;p&gt;
load 10 and put into stack position 1
&lt;/p&gt;
&lt;p&gt;
then put into dynamic types
&lt;/p&gt;
&lt;h2&gt;Named Arguments
&lt;/h2&gt;
&lt;p&gt;
Whats an argument and whats a parameter?
&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:b4dac9ec-2f0d-4d1b-b1b9-c8e423a803dc" class="wlWriterEditableSmartContent"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt;
&lt;div style="background-color: #ffffff; max-height: 400px; overflow: auto; padding: 2px 5px;"&gt;
&lt;span style="color:#0000ff"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; Main(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;[]
args)&lt;br&gt;
{&lt;br&gt;
&lt;span style="color:#008000"&gt;//provide an argument&lt;/span&gt;
&lt;br&gt;
Foo(&lt;span style="color:#a31515"&gt;&amp;quot;hello&amp;quot;&lt;/span&gt;);&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
&lt;span style="color:#008000"&gt;//x is a parameter&lt;/span&gt;
&lt;br&gt;
&lt;span style="color:#0000ff"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; Foo(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; x)&lt;br&gt;
{&lt;br&gt;
&lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(x);&lt;br&gt;
}&lt;br&gt;
}
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/Windows-Live-Writer/29d7293f30dc_C366/image_4.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/Windows-Live-Writer/29d7293f30dc_C366/image_thumb_1.png" width="270" height="353" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Got it the wrong way round.. hard to tell which is which in MessageBox.Show
&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:23b168ab-1590-4db7-8367-b86e9c979516" class="wlWriterEditableSmartContent"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt;
&lt;div style="background-color: #ffffff; max-height: 400px; overflow: auto; padding: 2px 5px;"&gt;
&lt;span style="color:#0000ff"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; Main(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;[]
args)&lt;br&gt;
{&lt;br&gt;
&lt;span style="color:#008000"&gt;//named argument C#4&lt;/span&gt;
&lt;br&gt;
Foo(x: &lt;span style="color:#a31515"&gt;&amp;quot;hello&amp;quot;&lt;/span&gt;, y:&lt;span style="color:#a31515"&gt;&amp;quot;Rob&amp;quot;&lt;/span&gt;);&lt;br&gt;
&lt;span style="color:#008000"&gt;//referenced System.Windows.Forms&lt;/span&gt;
&lt;br&gt;
&lt;span style="color:#2b91af"&gt;MessageBox&lt;/span&gt;.Show(caption:&lt;span style="color:#a31515"&gt;&amp;quot;title&amp;quot;&lt;/span&gt;,
text:&lt;span style="color:#a31515"&gt;&amp;quot;body&amp;quot;&lt;/span&gt;);&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
&lt;span style="color:#008000"&gt;//x is a parameter&lt;/span&gt;
&lt;br&gt;
&lt;span style="color:#0000ff"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; Foo(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; x, &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; y)&lt;br&gt;
{&lt;br&gt;
&lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(x + &lt;span style="color:#a31515"&gt;&amp;quot;
&amp;quot;&lt;/span&gt; + y);&lt;br&gt;
}
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
better!
&lt;/p&gt;
&lt;h2&gt;Optional Parameters
&lt;/h2&gt;
&lt;p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:af2b379f-46a9-43a6-bd15-e8c4cdb74cdc" class="wlWriterEditableSmartContent"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt;
&lt;div style="background-color: #ffffff; max-height: 400px; overflow: auto; padding: 2px 5px;"&gt;
&lt;span style="color:#0000ff"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; Main(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;[]
args)&lt;br&gt;
{&lt;br&gt;
&lt;span style="color:#008000"&gt;//named arguments&lt;/span&gt;
&lt;br&gt;
Foo(y: &lt;span style="color:#a31515"&gt;&amp;quot;Rob&amp;quot;&lt;/span&gt;);&lt;br&gt;
Foo(y: &lt;span style="color:#a31515"&gt;&amp;quot;Dave&amp;quot;&lt;/span&gt;);&lt;br&gt;
Foo(y: &lt;span style="color:#a31515"&gt;&amp;quot;Mike&amp;quot;&lt;/span&gt;);&lt;br&gt;
Foo(y: &lt;span style="color:#a31515"&gt;&amp;quot;Bill&amp;quot;&lt;/span&gt;);&lt;br&gt;
Foo(&lt;span style="color:#a31515"&gt;&amp;quot;Hi&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;Anders&amp;quot;&lt;/span&gt;);&lt;br&gt;
Foo();&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
&lt;span style="color:#008000"&gt;//optional parameters&lt;/span&gt;
&lt;br&gt;
&lt;span style="color:#008000"&gt;//if first parameter is optional all have to be&lt;/span&gt;
&lt;br&gt;
&lt;span style="color:#0000ff"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; Foo(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; x
= &lt;span style="color:#a31515"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; y
= &lt;span style="color:#a31515"&gt;&amp;quot;Everone&amp;quot;&lt;/span&gt;)&lt;br&gt;
{ 
&lt;br&gt;
&lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(x + &lt;span style="color:#a31515"&gt;&amp;quot;
&amp;quot;&lt;/span&gt; + y);&lt;br&gt;
}&lt;br&gt;
}
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&gt;
&lt;h2&gt;Covariance and Contravariance
&lt;/h2&gt;
&lt;p&gt;
Some code here.. poster child of the more used covariance is IEnumerable&amp;lt;T&amp;gt;..
look for out keword.&amp;#160; And it is to do with hierarchies.
&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e1a928d3-bffc-47df-b173-ef3b54e9eceb" class="wlWriterEditableSmartContent"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt;
&lt;div style="background-color: #ffffff; max-height: 400px; overflow: auto; padding: 2px 5px;"&gt;
&lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Fruit&lt;/span&gt; {
}&lt;br&gt;
&lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Banana&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;Fruit&lt;/span&gt; {
}&lt;br&gt;
&lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Apple&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;Fruit&lt;/span&gt; {
}&lt;br&gt;
&lt;br&gt;
&lt;span style="color:#008000"&gt;//interface IEnumerable&amp;lt;out T&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="color:#008000"&gt;//{&lt;/span&gt;
&lt;br&gt;
&lt;span style="color:#008000"&gt;// IEnumerator&amp;lt;T&amp;gt; GetEnumerator();&lt;/span&gt;
&lt;br&gt;
&lt;span style="color:#008000"&gt;//}&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span style="color:#008000"&gt;//interface IEnumerator&amp;lt;out T&amp;gt; : IDisposable&lt;/span&gt;
&lt;br&gt;
&lt;span style="color:#008000"&gt;//{&lt;/span&gt;
&lt;br&gt;
&lt;span style="color:#008000"&gt;// T Current { get; }&lt;/span&gt;
&lt;br&gt;
&lt;span style="color:#008000"&gt;// bool MoveNext();&lt;/span&gt;
&lt;br&gt;
&lt;span style="color:#008000"&gt;// void Reset();&lt;/span&gt;
&lt;br&gt;
&lt;span style="color:#008000"&gt;//}&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span style="color:#008000"&gt;//covariance values coming out of an interface&lt;/span&gt;
&lt;br&gt;
&lt;span style="color:#008000"&gt;//usually happens with IEnumerable of T&lt;/span&gt;
&lt;br&gt;
&lt;span style="color:#0000ff"&gt;interface&lt;/span&gt; &lt;span style="color:#2b91af"&gt;IFoo&lt;/span&gt;&amp;lt;&lt;span style="color:#0000ff"&gt;out&lt;/span&gt; T&amp;gt;&lt;br&gt;
{&lt;br&gt;
T GiveMeAnInstanceOfT();&lt;br&gt;
&lt;span style="color:#008000"&gt;//void TakeanInstanceOfT(T instance);&lt;/span&gt;
&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
&lt;span style="color:#008000"&gt;//contravariance is in&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Program&lt;/span&gt;
&lt;br&gt;
{&lt;br&gt;
&lt;span style="color:#0000ff"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; Main(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;[]
args)&lt;br&gt;
{&lt;br&gt;
&lt;span style="color:#008000"&gt;//List&amp;lt;Banana&amp;gt; bunchOfBananas = new List&amp;lt;Banana&amp;gt;();&lt;/span&gt;
&lt;br&gt;
&lt;span style="color:#2b91af"&gt;IFoo&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;Banana&lt;/span&gt;&amp;gt;
bunchOfBananas = &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;;&lt;br&gt;
&lt;br&gt;
&lt;span style="color:#008000"&gt;//cant convert from a list of banana to a list of fruit&lt;/span&gt;
&lt;br&gt;
&lt;span style="color:#008000"&gt;//List&amp;lt;Fruit&amp;gt; fruitBowl = new List&amp;lt;Banana&amp;gt;();&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span style="color:#008000"&gt;//List&amp;lt;Fruit&amp;gt; fruitBowl = bunchOfBananas;&lt;/span&gt;
&lt;br&gt;
&lt;span style="color:#008000"&gt;//fruitBowl.Add(new Apple());&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span style="color:#008000"&gt;//Banana banana = bunchOfBananas[0]; &lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span style="color:#008000"&gt;//IEnumerable - sequence..cant add.. can only observe&lt;/span&gt;
&lt;br&gt;
&lt;span style="color:#008000"&gt;//IEnumerable&amp;lt;Fruit&amp;gt; fruitBowl = bunchOfBananas;&lt;/span&gt;
&lt;br&gt;
&lt;span style="color:#2b91af"&gt;IFoo&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;Fruit&lt;/span&gt;&amp;gt;
fruitBowl = bunchOfBananas;&lt;br&gt;
}&lt;br&gt;
}
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=616d76f6-b63e-4e7e-b95d-313a442b6665" /&gt;</description>
      <category>c# language</category>
      <category>JonSkeet</category>
      <category>TekPub</category>
    </item>
    <item>
      <trackback:ping>http://www.programgood.net/Trackback.aspx?guid=3786ebe9-fe87-4f74-bcb5-8b4b20282a14</trackback:ping>
      <pingback:server>http://www.programgood.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.programgood.net/PermaLink,guid,3786ebe9-fe87-4f74-bcb5-8b4b20282a14.aspx</pingback:target>
      <dc:creator>Dave Mateer</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="http://stackoverflow.com/questions/2515796/deferred-execution-and-eager-evaluation">http://stackoverflow.com/questions/2515796/deferred-execution-and-eager-evaluation</a>
        </p>
        <img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=3786ebe9-fe87-4f74-bcb5-8b4b20282a14" />
      </body>
      <title>IEnumerable Yield Deferred / Lazy</title>
      <guid isPermaLink="false">http://www.programgood.net/PermaLink,guid,3786ebe9-fe87-4f74-bcb5-8b4b20282a14.aspx</guid>
      <link>http://www.programgood.net/2012/02/14/IEnumerableYieldDeferredLazy.aspx</link>
      <pubDate>Tue, 14 Feb 2012 22:11:30 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a href="http://stackoverflow.com/questions/2515796/deferred-execution-and-eager-evaluation"&gt;http://stackoverflow.com/questions/2515796/deferred-execution-and-eager-evaluation&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=3786ebe9-fe87-4f74-bcb5-8b4b20282a14" /&gt;</description>
      <category>c#</category>
      <category>c# language</category>
      <category>ienumerable</category>
      <category>yield</category>
    </item>
    <item>
      <trackback:ping>http://www.programgood.net/Trackback.aspx?guid=d564eef5-441c-4560-82eb-0436912a5e41</trackback:ping>
      <pingback:server>http://www.programgood.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.programgood.net/PermaLink,guid,d564eef5-441c-4560-82eb-0436912a5e41.aspx</pingback:target>
      <dc:creator>Dave Mateer</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
variables or local variables – declared inside methods
</p>
        <p>
fields – variable (public or private) that is a member of a class
</p>
        <p>
property – has a getter or setter
</p>
        <img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=d564eef5-441c-4560-82eb-0436912a5e41" />
      </body>
      <title>C# Names</title>
      <guid isPermaLink="false">http://www.programgood.net/PermaLink,guid,d564eef5-441c-4560-82eb-0436912a5e41.aspx</guid>
      <link>http://www.programgood.net/2011/12/27/CNames.aspx</link>
      <pubDate>Tue, 27 Dec 2011 04:07:14 GMT</pubDate>
      <description>&lt;p&gt;
variables or local variables – declared inside methods
&lt;/p&gt;
&lt;p&gt;
fields – variable (public or private) that is a member of a class
&lt;/p&gt;
&lt;p&gt;
property – has a getter or setter
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=d564eef5-441c-4560-82eb-0436912a5e41" /&gt;</description>
      <category>c# language</category>
    </item>
    <item>
      <trackback:ping>http://www.programgood.net/Trackback.aspx?guid=55e388fa-abfb-4959-b125-04a09d16e89f</trackback:ping>
      <pingback:server>http://www.programgood.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.programgood.net/PermaLink,guid,55e388fa-abfb-4959-b125-04a09d16e89f.aspx</pingback:target>
      <dc:creator>Dave Mateer</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="http://ayende.com/blog/4092/reviewing-nerddinner">http://ayende.com/blog/4092/reviewing-nerddinner</a>
        </p>
        <p>
          <a href="http://osherove.com/tdd-kata-2/">http://osherove.com/tdd-kata-2/</a>
        </p>
        <img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=55e388fa-abfb-4959-b125-04a09d16e89f" />
      </body>
      <title>Code Reviews, TDD, Kata</title>
      <guid isPermaLink="false">http://www.programgood.net/PermaLink,guid,55e388fa-abfb-4959-b125-04a09d16e89f.aspx</guid>
      <link>http://www.programgood.net/2011/05/26/CodeReviewsTDDKata.aspx</link>
      <pubDate>Thu, 26 May 2011 02:02:37 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a href="http://ayende.com/blog/4092/reviewing-nerddinner"&gt;http://ayende.com/blog/4092/reviewing-nerddinner&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://osherove.com/tdd-kata-2/"&gt;http://osherove.com/tdd-kata-2/&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=55e388fa-abfb-4959-b125-04a09d16e89f" /&gt;</description>
      <category>c# language</category>
    </item>
    <item>
      <trackback:ping>http://www.programgood.net/Trackback.aspx?guid=a33b0ca0-9974-4c89-a35d-6c3f1cff5750</trackback:ping>
      <pingback:server>http://www.programgood.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.programgood.net/PermaLink,guid,a33b0ca0-9974-4c89-a35d-6c3f1cff5750.aspx</pingback:target>
      <dc:creator>Dave Mateer</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/43343855be0a_13BB9/keithDave_2.jpg">
          <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="keithDave" border="0" alt="keithDave" src="http://www.programgood.net/content/binary/WindowsLiveWriter/43343855be0a_13BB9/keithDave_thumb.jpg" width="504" height="379" />
        </a>
        <p>
        </p>
        <p>
About a week ago Keith and I went on a ‘tramp’.. thats trekking.  We discussed
Sudoku (apologies to Helen, Phil, Nora and others for starting the challenge without
you..there was lots of time while walking to discuss strategy).
</p>
        <h3>TDD
</h3>
        <p>
A single test project is VS2010.  Everything in one file (!) and static methods
to make starting easier.
</p>
        <p>
Coding strategy was to firstly:
</p>
        <ul>
          <ul>
            <li>
find a way to check the sudoku was solved 
<ul><li>
Do all horizontal lines have only 1 to 9 used once 
</li><li>
Do all vertical columns have 1 to 9 used once 
</li><li>
Do all 3*3 squares have 1 to 9 used once 
</li></ul></li>
          </ul>
        </ul>
        <p>
So I wanted a method to check if Array has only 1 instance of each number.
</p>
        <div>
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">[TestClass]<br /><span style="color: #0000ff">public</span><span style="color: #0000ff">class</span> UnitTest1<br />
{<br /><span style="color: #008000">// Arrays are [row, col]</span><br /><span style="color: #008000">// 0,0 0,1 0,2</span><br /><span style="color: #008000">// 1,0 1,1 1,2</span><br /><br /><span style="color: #008000">// SECTION 1 - tests are all about testing if the sudoku
is solved</span><br /><span style="color: #008000">// Single Array</span><br />
[TestMethod]<br /><span style="color: #0000ff">public</span><span style="color: #0000ff">void</span> SingleArrayCheckerFailsWhenArrayTooShort()<br />
{<br /><span style="color: #0000ff">int</span>[] numbers = { 1, 2, 3, 4, 5, 6, 7, 8 };<br /><span style="color: #0000ff">bool</span> result = DoesArrayHaveOnlyOneInstanceOfEachNumber(numbers);<br />
Assert.AreEqual(<span style="color: #0000ff">false</span>, result);<br />
}</pre>
        </div>
        <div>
          <br />
        </div>
        <p>
and the Method:
</p>
        <div id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <span style="color: #0000ff">public</span>
            <span style="color: #0000ff">static</span>
            <span style="color: #0000ff">bool</span> DoesArrayHaveOnlyOneInstanceOfEachNumber(<span style="color: #0000ff">int</span>[]
arrayOfNumbers)<br />
{<br /><span style="color: #0000ff">if</span> (arrayOfNumbers.Length != 9)<br /><span style="color: #0000ff">return</span><span style="color: #0000ff">false</span>;<br /><br /><span style="color: #0000ff">if</span> (arrayOfNumbers.Contains(0))<br /><span style="color: #0000ff">throw</span><span style="color: #0000ff">new</span> Exception(<span style="color: #006080">"checking
of a line array contains a 0"</span>);<br /><br /><span style="color: #0000ff">int</span>[] howManyInstancesOfEachNumber = <span style="color: #0000ff">new</span><span style="color: #0000ff">int</span>[9]
{ 0, 0, 0, 0, 0, 0, 0, 0, 0 };<br /><br /><span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> i
= 0; i &lt; 9; i++)<br />
{<br /><span style="color: #0000ff">int</span> valueOfCurrentNumber = arrayOfNumbers[i];<br />
howManyInstancesOfEachNumber[valueOfCurrentNumber - 1] += 1;<br />
}<br /><br /><span style="color: #0000ff">foreach</span> (var result <span style="color: #0000ff">in</span> howManyInstancesOfEachNumber)<br />
{<br /><span style="color: #0000ff">if</span> (result != 1)<br /><span style="color: #0000ff">return</span><span style="color: #0000ff">false</span>;<br />
}<br /><br /><span style="color: #0000ff">return</span><span style="color: #0000ff">true</span>;<br />
}</pre>
          <br />
        </div>
        <p>
An array is Enumerable.
</p>
        <p>
then write the tests
</p>
        <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">[TestMethod]<br /><span style="color: #0000ff">public</span><span style="color: #0000ff">void</span> AllHorizonalLinesPass()<br />
{<br /><span style="color: #0000ff">int</span>[,] sudokuArray = <span style="color: #0000ff">new</span><span style="color: #0000ff">int</span>[9,
9]{ {1,2,3,4,5,6,7,8,9},<br />
{1,2,3,4,5,6,7,8,9},<br />
{1,2,3,4,5,6,7,8,9},<br />
{1,2,3,4,5,6,7,8,9},<br />
{1,2,3,4,5,6,7,8,9},<br />
{1,2,3,4,5,6,7,8,9},<br />
{1,2,3,4,5,6,7,8,9},<br />
{1,2,3,4,5,6,7,8,9},<br />
{1,2,3,4,5,6,7,8,9}<br />
};<br /><br /><span style="color: #0000ff">bool</span> result = DoAllHorizontalRowsPass(sudokuArray);<br />
Assert.AreEqual(<span style="color: #0000ff">true</span>, result);<br />
}<br /><br />
[TestMethod]<br /><span style="color: #0000ff">public</span><span style="color: #0000ff">void</span> AllVerticalColsPass()<br />
{<br /><span style="color: #0000ff">int</span>[,] sudokuArray = <span style="color: #0000ff">new</span><span style="color: #0000ff">int</span>[9,
9]{ {1,1,1,1,1,1,1,1,1},<br />
{2,2,2,2,2,2,2,2,2},<br />
{3,3,3,3,3,3,3,3,3},<br />
{4,4,4,4,4,4,4,4,4},<br />
{5,5,5,5,5,5,5,5,5},<br />
{6,6,6,6,6,6,6,6,6},<br />
{7,7,7,7,7,7,7,7,7},<br />
{8,8,8,8,8,8,8,8,8},<br />
{9,9,9,9,9,9,9,9,9}<br />
};<br /><br /><span style="color: #0000ff">bool</span> result = DoAllVerticalColsPass(sudokuArray);<br />
Assert.AreEqual(<span style="color: #0000ff">true</span>, result);<br />
}<br /><br />
[TestMethod]<br /><span style="color: #0000ff">public</span><span style="color: #0000ff">void</span> AllSquaresPass()<br />
{<br /><span style="color: #0000ff">int</span>[,] sudokuArray = <span style="color: #0000ff">new</span><span style="color: #0000ff">int</span>[9,
9]{ {1,2,3,1,2,3,1,2,3},<br />
{4,5,6,4,5,6,4,5,6},<br />
{7,8,9,7,8,9,7,8,9},<br />
{7,8,9,7,8,9,7,8,9},<br />
{4,5,6,4,5,6,4,5,6},<br />
{1,2,3,1,2,3,1,2,3},<br />
{4,5,6,4,5,6,4,5,6},<br />
{1,2,3,1,2,3,1,2,3},<br />
{7,8,9,7,8,9,7,8,9},<br />
};<br /><br /><span style="color: #0000ff">bool</span> result = DoAllSquaresPass(sudokuArray);<br />
Assert.AreEqual(<span style="color: #0000ff">true</span>, result);<br />
}</pre>
          <br />
        </div>
        <p>
then make them pass:
</p>
        <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <span style="color: #0000ff">public</span>
            <span style="color: #0000ff">static</span>
            <span style="color: #0000ff">bool</span> DoAllHorizontalRowsPass(<span style="color: #0000ff">int</span>[,]
sudoku)<br />
{<br /><span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> row
= 0; row &lt; 9; row++) <span style="color: #008000">// go over each horizontal line</span><br />
{<br /><span style="color: #0000ff">int</span>[] horizonalLineArray = <span style="color: #0000ff">new</span><span style="color: #0000ff">int</span>[9];<br /><span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> col
= 0; col &lt; 9; col++) <span style="color: #008000">// get each number in that line
and put into a new horizontalLineArray</span><br />
horizonalLineArray[col] = sudoku[row, col];<br /><br /><span style="color: #0000ff">if</span> (!DoesArrayHaveOnlyOneInstanceOfEachNumber(horizonalLineArray))<br /><span style="color: #0000ff">return</span><span style="color: #0000ff">false</span>;<br />
}<br /><span style="color: #0000ff">return</span><span style="color: #0000ff">true</span>;<br />
}<br /><br /><span style="color: #0000ff">public</span><span style="color: #0000ff">static</span><span style="color: #0000ff">bool</span> DoAllVerticalColsPass(<span style="color: #0000ff">int</span>[,]
sudoku)<br />
{<br /><span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> col
= 0; col &lt; 9; col++) <span style="color: #008000">// go over each vertical line</span><br />
{<br /><span style="color: #0000ff">int</span>[] verticalLineArray = <span style="color: #0000ff">new</span><span style="color: #0000ff">int</span>[9];<br /><br /><span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> row
= 0; row &lt; 9; row++) <span style="color: #008000">// get each number in that vertical
line and put into a new verticalLineArray</span><br />
verticalLineArray[row] = sudoku[row, col];<br /><br /><span style="color: #0000ff">if</span> (!DoesArrayHaveOnlyOneInstanceOfEachNumber(verticalLineArray))<br /><span style="color: #0000ff">return</span><span style="color: #0000ff">false</span>;<br />
}<br /><span style="color: #0000ff">return</span><span style="color: #0000ff">true</span>;<br />
}<br /><br /><span style="color: #0000ff">public</span><span style="color: #0000ff">static</span><span style="color: #0000ff">bool</span> DoAllSquaresPass(<span style="color: #0000ff">int</span>[,]
sudoku)<br />
{<br /><span style="color: #0000ff">int</span> rowStart = 0;<br /><span style="color: #0000ff">int</span> rowEnd = 2;<br /><span style="color: #0000ff">int</span> colStart = 0;<br /><span style="color: #0000ff">int</span> colEnd = 2;<br /><br /><span style="color: #0000ff">int</span> squareCounter = 1;<br /><span style="color: #0000ff">while</span> (squareCounter &lt; 9) <span style="color: #008000">//
take each 3*3 square and test it</span><br />
{<br /><span style="color: #0000ff">int</span>[] allNumbersInSquareArray = <span style="color: #0000ff">new</span><span style="color: #0000ff">int</span>[9];<br /><span style="color: #008000">// go over first 3*3 square</span><br /><span style="color: #0000ff">int</span> counter = 0;<br /><span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> row
= rowStart; row &lt;= rowEnd; row++)<br />
{<br /><span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> col
= colStart; col &lt;= colEnd; col++)<br />
{<br />
allNumbersInSquareArray[counter] = sudoku[row, col];<br />
counter++;<br />
}<br />
}<br /><br /><span style="color: #0000ff">if</span> (!DoesArrayHaveOnlyOneInstanceOfEachNumber(allNumbersInSquareArray))<br /><span style="color: #0000ff">return</span><span style="color: #0000ff">false</span>;<br /><br /><span style="color: #008000">// increment to the next 3*3 square going along horizontally
first</span><br /><span style="color: #0000ff">if</span> (colEnd != 8)<br />
{<br />
colStart += 3;<br />
colEnd += 3;<br />
}<br /><span style="color: #0000ff">else</span><span style="color: #008000">// go down to
next 'row' of squares</span><br />
{<br />
colStart = 0;<br />
colEnd = 2;<br />
rowStart += 3;<br />
rowEnd += 3;<br />
}<br /><br />
squareCounter++;<br />
}<br /><span style="color: #0000ff">return</span><span style="color: #0000ff">true</span>;<br />
}</pre>
          <br />
        </div>
        <p>
        </p>
        <h3>Making a Solver
</h3>
        <p>
Strategy was to (For all the elements with 0 in them):
</p>
        <ul>
          <li>
Get rid of numbers 
<ul><li>
LookAtOtherNumbersInRowAndTakeOutOnesWeDontNeedToCheck 
</li><li>
LookAtOtherNumbersInColumnAndTakeOutOnesWeDontNeedToCheck 
</li><li>
LookAtOtherNumbersInSquareAndTakeOutOnesWeDontNeed 
</li><li>
Then select a random number from the ones left 
</li><li>
check if sudoku is solved 
</li></ul></li>
        </ul>
        <p>
I used TDD on each Method eg
</p>
        <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">[TestMethod]<br /><span style="color: #0000ff">public</span><span style="color: #0000ff">void</span> LookAtOtherNumbersInRowAndTakeThoseOffTheListOfNumbersToTry()<br />
{<br /><span style="color: #0000ff">int</span> row = 2;<br />
List&lt;<span style="color: #0000ff">int</span>&gt; listOfNumbersToTry = <span style="color: #0000ff">new</span> List&lt;<span style="color: #0000ff">int</span>&gt;();<br /><span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> i
= 1; i &lt; 10; i++)<br />
listOfNumbersToTry.Add(i);<br /><br /><span style="color: #0000ff">int</span>[,] trySudokuArray = <span style="color: #0000ff">new</span><span style="color: #0000ff">int</span>[9,
9]{ {1,2,3,4,5,6,7,8,9},<br />
{1,2,3,4,5,6,7,8,9},<br />
{1,2,0,4,5,6,0,8,0}, <span style="color: #008000">// this one</span><br />
{1,2,3,4,5,6,7,8,9},<br />
{1,2,3,4,5,6,7,8,9},<br />
{1,2,3,4,5,6,7,8,9},<br />
{1,2,3,4,5,6,7,8,9},<br />
{1,2,3,4,5,6,7,8,9},<br />
{1,2,3,4,5,6,7,8,9}<br />
};<br />
LookAtOtherNumbersInRowAndTakeOutOnesWeDontNeedToCheck(trySudokuArray, row, listOfNumbersToTry);<br /><br />
Assert.AreEqual(3, listOfNumbersToTry.Count);<br />
Assert.IsTrue(listOfNumbersToTry.Contains(3));<br />
Assert.IsTrue(listOfNumbersToTry.Contains(7));<br />
Assert.IsTrue(listOfNumbersToTry.Contains(9));<br />
}</pre>
          <br />
        </div>
        <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <span style="color: #008000">//level
1</span>
            <br />
            <span style="color: #0000ff">public</span>
            <span style="color: #0000ff">static</span>
            <span style="color: #0000ff">int</span>[,]
solve(<span style="color: #0000ff">int</span>[,] inputSudokuArray) {<br /><br /><span style="color: #008000">// fill in numbers which are correct</span><br /><span style="color: #008000">//int[,] sudokuArrayAfterB = new int[9, 9];</span><br /><span style="color: #008000">//sudokuArrayAfterB = solveB(inputSudokuArray);</span><br /><br /><span style="color: #008000">// semi random code</span><br />
Random random = <span style="color: #0000ff">new</span> Random();<br /><span style="color: #0000ff">bool</span> isSolved = <span style="color: #0000ff">false</span>;<br /><span style="color: #0000ff">int</span> numberOfIterations = 0;<br /><br /><span style="color: #0000ff">while</span> (!isSolved)<br />
{<br /><span style="color: #0000ff">int</span>[,] trySudokuArray = (<span style="color: #0000ff">int</span>[,])sudokuArrayAfterB.Clone();<br /><span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> row
= 0; row &lt; 9; row++)<br />
{<br /><span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> col
= 0; col &lt; 9; col++)<br />
{<br /><span style="color: #0000ff">if</span> (trySudokuArray[row,col] == 0) <span style="color: #008000">//
if it is blank</span><br />
{<br /><span style="color: #008000">// setup numbers to try, then strategy is to take out
of this list</span><br />
List&lt;<span style="color: #0000ff">int</span>&gt; listOfNumbersToTry = <span style="color: #0000ff">new</span> List&lt;<span style="color: #0000ff">int</span>&gt;();<br /><span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> i
= 1; i &lt; 10; i++)<br />
listOfNumbersToTry.Add(i);<br /><br />
LookAtOtherNumbersInRowAndTakeOutOnesWeDontNeedToCheck(trySudokuArray, row, listOfNumbersToTry);<br /><br />
LookAtOtherNumbersInColumnAndTakeOutOnesWeDontNeedToCheck(trySudokuArray, col, listOfNumbersToTry);<br /><br />
LookAtOtherNumbersInSquareAndTakeOutOnesWeDontNeed(trySudokuArray, row, col, listOfNumbersToTry);<br /><br /><span style="color: #008000">// are there any possible numbers?</span><br /><span style="color: #0000ff">if</span> (listOfNumbersToTry.Count &gt; 0)<br />
{<br /><span style="color: #008000">// pick a random number from listOfNumbersToTry</span><br /><span style="color: #0000ff">int</span> indexOfListNumberToGet = random.Next(0, listOfNumbersToTry.Count());<br />
trySudokuArray[row,col] = listOfNumbersToTry[indexOfListNumberToGet];<br />
}<br /><span style="color: #0000ff">else</span><br /><span style="color: #0000ff">goto</span> Foo;<br />
}<br />
}<br />
}<br />
isSolved = checkSudoku(trySudokuArray);<br /><br /><span style="color: #0000ff">if</span> (isSolved)<br />
{<br /><span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> row
= 0; row &lt; 9; row++)<br />
{<br /><span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> col
= 0; col &lt; 9; col++)<br />
Debug.Write(trySudokuArray[row, col] + <span style="color: #006080">" "</span>);<br />
Debug.WriteLine(<span style="color: #006080">""</span>);<br />
}<br /><span style="color: #0000ff">return</span> trySudokuArray;<br />
}<br />
Foo:<br /><span style="color: #0000ff">if</span> (numberOfIterations % 1000 == 0)<br />
Debug.WriteLine(<span style="color: #006080">"iterations: "</span> + String.Format(<span style="color: #006080">"{0:0,0}"</span>,numberOfIterations));<br /><span style="color: #008000">//Console.WriteLine("iterations: " + String.Format("{0:0,0}",
numberOfIterations));</span><br />
numberOfIterations++;<br />
}<br /><span style="color: #0000ff">return</span><span style="color: #0000ff">null</span>;<br />
}</pre>
          <br />
        </div>
        <blockquote>
          <p>
 
</p>
        </blockquote>
        <p>
        </p>
        <h3>StrategyB – Make numbers definite if we know they are
</h3>
        <ul>
          <li>
For each 0 square see if there is only 1 possible number 
<ul><li>
ie look at LookAtOtherNumbersInRowAndTakeOutOnesWeDontNeedToCheck etc 
</li><li>
put that number in the square 
</li><li>
keep looping the whole board until nothing is changed 
</li></ul></li>
        </ul>
        <img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=a33b0ca0-9974-4c89-a35d-6c3f1cff5750" />
      </body>
      <title>Sudoku</title>
      <guid isPermaLink="false">http://www.programgood.net/PermaLink,guid,a33b0ca0-9974-4c89-a35d-6c3f1cff5750.aspx</guid>
      <link>http://www.programgood.net/2011/04/10/Sudoku.aspx</link>
      <pubDate>Sun, 10 Apr 2011 07:40:37 GMT</pubDate>
      <description>&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/43343855be0a_13BB9/keithDave_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="keithDave" border="0" alt="keithDave" src="http://www.programgood.net/content/binary/WindowsLiveWriter/43343855be0a_13BB9/keithDave_thumb.jpg" width="504" height="379" /&gt;&lt;/a&gt; 
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
About a week ago Keith and I went on a ‘tramp’.. thats trekking.&amp;#160; We discussed
Sudoku (apologies to Helen, Phil, Nora and others for starting the challenge without
you..there was lots of time while walking to discuss strategy).
&lt;/p&gt;
&lt;h3&gt;TDD
&lt;/h3&gt;
&lt;p&gt;
A single test project is VS2010.&amp;#160; Everything in one file (!) and static methods
to make starting easier.
&lt;/p&gt;
&lt;p&gt;
Coding strategy was to firstly:
&lt;/p&gt;
&lt;ul&gt;
&lt;ul&gt;
&lt;li&gt;
find a way to check the sudoku was solved 
&lt;ul&gt;
&lt;li&gt;
Do all horizontal lines have only 1 to 9 used once 
&lt;/li&gt;
&lt;li&gt;
Do all vertical columns have 1 to 9 used once 
&lt;/li&gt;
&lt;li&gt;
Do all 3*3 squares have 1 to 9 used once 
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
&lt;p&gt;
So I wanted a method to check if Array has only 1 instance of each number.
&lt;/p&gt;
&lt;div&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;[TestClass]&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; UnitTest1&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #008000"&gt;// Arrays are [row, col]&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;// 0,0 0,1 0,2&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;// 1,0 1,1 1,2&lt;/span&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;// SECTION 1 - tests are all about testing if the sudoku
is solved&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;// Single Array&lt;/span&gt;
&lt;br /&gt;
[TestMethod]&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; SingleArrayCheckerFailsWhenArrayTooShort()&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;[] numbers = { 1, 2, 3, 4, 5, 6, 7, 8 };&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; result = DoesArrayHaveOnlyOneInstanceOfEachNumber(numbers);&lt;br /&gt;
Assert.AreEqual(&lt;span style="color: #0000ff"&gt;false&lt;/span&gt;, result);&lt;br /&gt;
}&lt;/pre&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
and the Method:
&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; DoesArrayHaveOnlyOneInstanceOfEachNumber(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;[]
arrayOfNumbers)&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (arrayOfNumbers.Length != 9)&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (arrayOfNumbers.Contains(0))&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Exception(&lt;span style="color: #006080"&gt;&amp;quot;checking
of a line array contains a 0&amp;quot;&lt;/span&gt;);&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;[] howManyInstancesOfEachNumber = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;[9]
{ 0, 0, 0, 0, 0, 0, 0, 0, 0 };&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;for&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; i
= 0; i &amp;lt; 9; i++)&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; valueOfCurrentNumber = arrayOfNumbers[i];&lt;br /&gt;
howManyInstancesOfEachNumber[valueOfCurrentNumber - 1] += 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (var result &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; howManyInstancesOfEachNumber)&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (result != 1)&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;;&lt;br /&gt;
}&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
An array is Enumerable.
&lt;/p&gt;
&lt;p&gt;
then write the tests
&lt;/p&gt;
&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;[TestMethod]&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; AllHorizonalLinesPass()&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;[,] sudokuArray = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;[9,
9]{ {1,2,3,4,5,6,7,8,9},&lt;br /&gt;
{1,2,3,4,5,6,7,8,9},&lt;br /&gt;
{1,2,3,4,5,6,7,8,9},&lt;br /&gt;
{1,2,3,4,5,6,7,8,9},&lt;br /&gt;
{1,2,3,4,5,6,7,8,9},&lt;br /&gt;
{1,2,3,4,5,6,7,8,9},&lt;br /&gt;
{1,2,3,4,5,6,7,8,9},&lt;br /&gt;
{1,2,3,4,5,6,7,8,9},&lt;br /&gt;
{1,2,3,4,5,6,7,8,9}&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; result = DoAllHorizontalRowsPass(sudokuArray);&lt;br /&gt;
Assert.AreEqual(&lt;span style="color: #0000ff"&gt;true&lt;/span&gt;, result);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
[TestMethod]&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; AllVerticalColsPass()&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;[,] sudokuArray = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;[9,
9]{ {1,1,1,1,1,1,1,1,1},&lt;br /&gt;
{2,2,2,2,2,2,2,2,2},&lt;br /&gt;
{3,3,3,3,3,3,3,3,3},&lt;br /&gt;
{4,4,4,4,4,4,4,4,4},&lt;br /&gt;
{5,5,5,5,5,5,5,5,5},&lt;br /&gt;
{6,6,6,6,6,6,6,6,6},&lt;br /&gt;
{7,7,7,7,7,7,7,7,7},&lt;br /&gt;
{8,8,8,8,8,8,8,8,8},&lt;br /&gt;
{9,9,9,9,9,9,9,9,9}&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; result = DoAllVerticalColsPass(sudokuArray);&lt;br /&gt;
Assert.AreEqual(&lt;span style="color: #0000ff"&gt;true&lt;/span&gt;, result);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
[TestMethod]&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; AllSquaresPass()&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;[,] sudokuArray = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;[9,
9]{ {1,2,3,1,2,3,1,2,3},&lt;br /&gt;
{4,5,6,4,5,6,4,5,6},&lt;br /&gt;
{7,8,9,7,8,9,7,8,9},&lt;br /&gt;
{7,8,9,7,8,9,7,8,9},&lt;br /&gt;
{4,5,6,4,5,6,4,5,6},&lt;br /&gt;
{1,2,3,1,2,3,1,2,3},&lt;br /&gt;
{4,5,6,4,5,6,4,5,6},&lt;br /&gt;
{1,2,3,1,2,3,1,2,3},&lt;br /&gt;
{7,8,9,7,8,9,7,8,9},&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; result = DoAllSquaresPass(sudokuArray);&lt;br /&gt;
Assert.AreEqual(&lt;span style="color: #0000ff"&gt;true&lt;/span&gt;, result);&lt;br /&gt;
}&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
then make them pass:
&lt;/p&gt;
&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; DoAllHorizontalRowsPass(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;[,]
sudoku)&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;for&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; row
= 0; row &amp;lt; 9; row++) &lt;span style="color: #008000"&gt;// go over each horizontal line&lt;/span&gt;
&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;[] horizonalLineArray = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;[9];&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;for&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; col
= 0; col &amp;lt; 9; col++) &lt;span style="color: #008000"&gt;// get each number in that line
and put into a new horizontalLineArray&lt;/span&gt;
&lt;br /&gt;
horizonalLineArray[col] = sudoku[row, col];&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!DoesArrayHaveOnlyOneInstanceOfEachNumber(horizonalLineArray))&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;;&lt;br /&gt;
}&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; DoAllVerticalColsPass(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;[,]
sudoku)&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;for&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; col
= 0; col &amp;lt; 9; col++) &lt;span style="color: #008000"&gt;// go over each vertical line&lt;/span&gt;
&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;[] verticalLineArray = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;[9];&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;for&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; row
= 0; row &amp;lt; 9; row++) &lt;span style="color: #008000"&gt;// get each number in that vertical
line and put into a new verticalLineArray&lt;/span&gt;
&lt;br /&gt;
verticalLineArray[row] = sudoku[row, col];&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!DoesArrayHaveOnlyOneInstanceOfEachNumber(verticalLineArray))&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;;&lt;br /&gt;
}&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; DoAllSquaresPass(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;[,]
sudoku)&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; rowStart = 0;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; rowEnd = 2;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; colStart = 0;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; colEnd = 2;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; squareCounter = 1;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;while&lt;/span&gt; (squareCounter &amp;lt; 9) &lt;span style="color: #008000"&gt;//
take each 3*3 square and test it&lt;/span&gt;
&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;[] allNumbersInSquareArray = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;[9];&lt;br /&gt;
&lt;span style="color: #008000"&gt;// go over first 3*3 square&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; counter = 0;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;for&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; row
= rowStart; row &amp;lt;= rowEnd; row++)&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;for&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; col
= colStart; col &amp;lt;= colEnd; col++)&lt;br /&gt;
{&lt;br /&gt;
allNumbersInSquareArray[counter] = sudoku[row, col];&lt;br /&gt;
counter++;&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!DoesArrayHaveOnlyOneInstanceOfEachNumber(allNumbersInSquareArray))&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;// increment to the next 3*3 square going along horizontally
first&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (colEnd != 8)&lt;br /&gt;
{&lt;br /&gt;
colStart += 3;&lt;br /&gt;
colEnd += 3;&lt;br /&gt;
}&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;else&lt;/span&gt; &lt;span style="color: #008000"&gt;// go down to
next 'row' of squares&lt;/span&gt;
&lt;br /&gt;
{&lt;br /&gt;
colStart = 0;&lt;br /&gt;
colEnd = 2;&lt;br /&gt;
rowStart += 3;&lt;br /&gt;
rowEnd += 3;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
squareCounter++;&lt;br /&gt;
}&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;;&lt;br /&gt;
}&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;h3&gt;Making a Solver
&lt;/h3&gt;
&lt;p&gt;
Strategy was to (For all the elements with 0 in them):
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Get rid of numbers 
&lt;ul&gt;
&lt;li&gt;
LookAtOtherNumbersInRowAndTakeOutOnesWeDontNeedToCheck 
&lt;/li&gt;
&lt;li&gt;
LookAtOtherNumbersInColumnAndTakeOutOnesWeDontNeedToCheck 
&lt;/li&gt;
&lt;li&gt;
LookAtOtherNumbersInSquareAndTakeOutOnesWeDontNeed 
&lt;/li&gt;
&lt;li&gt;
Then select a random number from the ones left 
&lt;/li&gt;
&lt;li&gt;
check if sudoku is solved 
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
I used TDD on each Method eg
&lt;/p&gt;
&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;[TestMethod]&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; LookAtOtherNumbersInRowAndTakeThoseOffTheListOfNumbersToTry()&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; row = 2;&lt;br /&gt;
List&amp;lt;&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;&amp;gt; listOfNumbersToTry = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; List&amp;lt;&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;&amp;gt;();&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;for&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; i
= 1; i &amp;lt; 10; i++)&lt;br /&gt;
listOfNumbersToTry.Add(i);&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;[,] trySudokuArray = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;[9,
9]{ {1,2,3,4,5,6,7,8,9},&lt;br /&gt;
{1,2,3,4,5,6,7,8,9},&lt;br /&gt;
{1,2,0,4,5,6,0,8,0}, &lt;span style="color: #008000"&gt;// this one&lt;/span&gt;
&lt;br /&gt;
{1,2,3,4,5,6,7,8,9},&lt;br /&gt;
{1,2,3,4,5,6,7,8,9},&lt;br /&gt;
{1,2,3,4,5,6,7,8,9},&lt;br /&gt;
{1,2,3,4,5,6,7,8,9},&lt;br /&gt;
{1,2,3,4,5,6,7,8,9},&lt;br /&gt;
{1,2,3,4,5,6,7,8,9}&lt;br /&gt;
};&lt;br /&gt;
LookAtOtherNumbersInRowAndTakeOutOnesWeDontNeedToCheck(trySudokuArray, row, listOfNumbersToTry);&lt;br /&gt;
&lt;br /&gt;
Assert.AreEqual(3, listOfNumbersToTry.Count);&lt;br /&gt;
Assert.IsTrue(listOfNumbersToTry.Contains(3));&lt;br /&gt;
Assert.IsTrue(listOfNumbersToTry.Contains(7));&lt;br /&gt;
Assert.IsTrue(listOfNumbersToTry.Contains(9));&lt;br /&gt;
}&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #008000"&gt;//level
1&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;[,]
solve(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;[,] inputSudokuArray) {&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;// fill in numbers which are correct&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;//int[,] sudokuArrayAfterB = new int[9, 9];&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;//sudokuArrayAfterB = solveB(inputSudokuArray);&lt;/span&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;// semi random code&lt;/span&gt;
&lt;br /&gt;
Random random = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Random();&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; isSolved = &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; numberOfIterations = 0;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;while&lt;/span&gt; (!isSolved)&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;[,] trySudokuArray = (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;[,])sudokuArrayAfterB.Clone();&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;for&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; row
= 0; row &amp;lt; 9; row++)&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;for&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; col
= 0; col &amp;lt; 9; col++)&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (trySudokuArray[row,col] == 0) &lt;span style="color: #008000"&gt;//
if it is blank&lt;/span&gt;
&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #008000"&gt;// setup numbers to try, then strategy is to take out
of this list&lt;/span&gt;
&lt;br /&gt;
List&amp;lt;&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;&amp;gt; listOfNumbersToTry = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; List&amp;lt;&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;&amp;gt;();&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;for&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; i
= 1; i &amp;lt; 10; i++)&lt;br /&gt;
listOfNumbersToTry.Add(i);&lt;br /&gt;
&lt;br /&gt;
LookAtOtherNumbersInRowAndTakeOutOnesWeDontNeedToCheck(trySudokuArray, row, listOfNumbersToTry);&lt;br /&gt;
&lt;br /&gt;
LookAtOtherNumbersInColumnAndTakeOutOnesWeDontNeedToCheck(trySudokuArray, col, listOfNumbersToTry);&lt;br /&gt;
&lt;br /&gt;
LookAtOtherNumbersInSquareAndTakeOutOnesWeDontNeed(trySudokuArray, row, col, listOfNumbersToTry);&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;// are there any possible numbers?&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (listOfNumbersToTry.Count &amp;gt; 0)&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #008000"&gt;// pick a random number from listOfNumbersToTry&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; indexOfListNumberToGet = random.Next(0, listOfNumbersToTry.Count());&lt;br /&gt;
trySudokuArray[row,col] = listOfNumbersToTry[indexOfListNumberToGet];&lt;br /&gt;
}&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;else&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;goto&lt;/span&gt; Foo;&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
isSolved = checkSudoku(trySudokuArray);&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (isSolved)&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;for&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; row
= 0; row &amp;lt; 9; row++)&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;for&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; col
= 0; col &amp;lt; 9; col++)&lt;br /&gt;
Debug.Write(trySudokuArray[row, col] + &lt;span style="color: #006080"&gt;&amp;quot; &amp;quot;&lt;/span&gt;);&lt;br /&gt;
Debug.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;&amp;quot;&lt;/span&gt;);&lt;br /&gt;
}&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;return&lt;/span&gt; trySudokuArray;&lt;br /&gt;
}&lt;br /&gt;
Foo:&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (numberOfIterations % 1000 == 0)&lt;br /&gt;
Debug.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;iterations: &amp;quot;&lt;/span&gt; + String.Format(&lt;span style="color: #006080"&gt;&amp;quot;{0:0,0}&amp;quot;&lt;/span&gt;,numberOfIterations));&lt;br /&gt;
&lt;span style="color: #008000"&gt;//Console.WriteLine(&amp;quot;iterations: &amp;quot; + String.Format(&amp;quot;{0:0,0}&amp;quot;,
numberOfIterations));&lt;/span&gt;
&lt;br /&gt;
numberOfIterations++;&lt;br /&gt;
}&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;;&lt;br /&gt;
}&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
&lt;/p&gt;
&lt;h3&gt;StrategyB – Make numbers definite if we know they are
&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
For each 0 square see if there is only 1 possible number 
&lt;ul&gt;
&lt;li&gt;
ie look at LookAtOtherNumbersInRowAndTakeOutOnesWeDontNeedToCheck etc 
&lt;/li&gt;
&lt;li&gt;
put that number in the square 
&lt;/li&gt;
&lt;li&gt;
keep looping the whole board until nothing is changed 
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=a33b0ca0-9974-4c89-a35d-6c3f1cff5750" /&gt;</description>
      <category>c# language</category>
      <category>Coding Challenge</category>
    </item>
    <item>
      <trackback:ping>http://www.programgood.net/Trackback.aspx?guid=90490c25-1acf-405d-a59b-0091c93b1aad</trackback:ping>
      <pingback:server>http://www.programgood.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.programgood.net/PermaLink,guid,90490c25-1acf-405d-a59b-0091c93b1aad.aspx</pingback:target>
      <dc:creator>Dave Mateer</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <div id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">[TestMethod]<br /><span style="color: #0000ff">public</span><span style="color: #0000ff">void</span> UnitTestThings()<br />
{<br />
Thing thing = <span style="color: #0000ff">new</span> Thing();<br />
IEnumerable&lt;Thing&gt; listOfThings = thing.giveMeAllThings(); 
<br />
Assert.AreEqual(3, listOfThings.Count()); <span style="color: #008000">// linq count</span><br />
Assert.IsTrue(listOfThings.Any(t =&gt; t.name == <span style="color: #006080">"phone"</span> &amp;&amp;
t.age == 3));<br />
Assert.IsTrue(listOfThings.Any(t =&gt; t.name == <span style="color: #006080">"waterbottle"</span> &amp;&amp;
t.age == 2));<br />
Assert.IsTrue(listOfThings.Any(t =&gt; t.name == <span style="color: #006080">"pinecone"</span> &amp;&amp;
t.age == 17));<br />
}</pre>
          <br />
        </div>
        <p>
Collection assertions <a href="http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.collectionassert.aspx">http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.collectionassert.aspx</a></p>
        <p>
this is different from Contains:
</p>
        <div id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">[TestMethod]<br /><span style="color: #0000ff">public</span><span style="color: #0000ff">void</span> when_asked_for_all_of_the_movies_it_should_receive_a_set_containing_each_movie_in_the_library()<br />
{<br />
Movie first_movie = <span style="color: #0000ff">new</span> Movie();<br />
Movie second_movie = <span style="color: #0000ff">new</span> Movie();<br />
movie_collection.Add(first_movie);<br />
movie_collection.Add(second_movie);<br /><br />
MovieLibrary movieLibrary = <span style="color: #0000ff">new</span> MovieLibrary(movie_collection);<br /><br />
IEnumerable&lt;Movie&gt; all_movies = movieLibrary.all_movies();<br /><br />
Assert.IsTrue(all_movies.Contains(first_movie));<br />
Assert.IsTrue(all_movies.Contains(second_movie));<br />
}</pre>
          <br />
        </div>
        <img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=90490c25-1acf-405d-a59b-0091c93b1aad" />
      </body>
      <title>Asserting something is in a Collection</title>
      <guid isPermaLink="false">http://www.programgood.net/PermaLink,guid,90490c25-1acf-405d-a59b-0091c93b1aad.aspx</guid>
      <link>http://www.programgood.net/2011/03/07/AssertingSomethingIsInACollection.aspx</link>
      <pubDate>Mon, 07 Mar 2011 10:54:41 GMT</pubDate>
      <description>&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;[TestMethod]&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; UnitTestThings()&lt;br /&gt;
{&lt;br /&gt;
Thing thing = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Thing();&lt;br /&gt;
IEnumerable&amp;lt;Thing&amp;gt; listOfThings = thing.giveMeAllThings(); 
&lt;br /&gt;
Assert.AreEqual(3, listOfThings.Count()); &lt;span style="color: #008000"&gt;// linq count&lt;/span&gt;
&lt;br /&gt;
Assert.IsTrue(listOfThings.Any(t =&amp;gt; t.name == &lt;span style="color: #006080"&gt;&amp;quot;phone&amp;quot;&lt;/span&gt; &amp;amp;&amp;amp;
t.age == 3));&lt;br /&gt;
Assert.IsTrue(listOfThings.Any(t =&amp;gt; t.name == &lt;span style="color: #006080"&gt;&amp;quot;waterbottle&amp;quot;&lt;/span&gt; &amp;amp;&amp;amp;
t.age == 2));&lt;br /&gt;
Assert.IsTrue(listOfThings.Any(t =&amp;gt; t.name == &lt;span style="color: #006080"&gt;&amp;quot;pinecone&amp;quot;&lt;/span&gt; &amp;amp;&amp;amp;
t.age == 17));&lt;br /&gt;
}&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
Collection assertions &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.collectionassert.aspx"&gt;http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.collectionassert.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
this is different from Contains:
&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;[TestMethod]&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; when_asked_for_all_of_the_movies_it_should_receive_a_set_containing_each_movie_in_the_library()&lt;br /&gt;
{&lt;br /&gt;
Movie first_movie = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Movie();&lt;br /&gt;
Movie second_movie = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Movie();&lt;br /&gt;
movie_collection.Add(first_movie);&lt;br /&gt;
movie_collection.Add(second_movie);&lt;br /&gt;
&lt;br /&gt;
MovieLibrary movieLibrary = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; MovieLibrary(movie_collection);&lt;br /&gt;
&lt;br /&gt;
IEnumerable&amp;lt;Movie&amp;gt; all_movies = movieLibrary.all_movies();&lt;br /&gt;
&lt;br /&gt;
Assert.IsTrue(all_movies.Contains(first_movie));&lt;br /&gt;
Assert.IsTrue(all_movies.Contains(second_movie));&lt;br /&gt;
}&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=90490c25-1acf-405d-a59b-0091c93b1aad" /&gt;</description>
      <category>c# language</category>
      <category>Testing</category>
    </item>
    <item>
      <trackback:ping>http://www.programgood.net/Trackback.aspx?guid=b3fe2704-ba3a-4437-b5de-db01edb19358</trackback:ping>
      <pingback:server>http://www.programgood.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.programgood.net/PermaLink,guid,b3fe2704-ba3a-4437-b5de-db01edb19358.aspx</pingback:target>
      <dc:creator>Dave Mateer</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <div id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">[TestMethod]<br /><span style="color: #0000ff">public</span><span style="color: #0000ff">void</span> when_sorting_movies_it_should_be_able_to_sort_all_movies_by_title_descending()<br />
{<br />
populateTestMovies(movie_collection);<br />
MovieLibrary movieLibrary = <span style="color: #0000ff">new</span> MovieLibrary(movie_collection);<br />
IEnumerable&lt;Movie&gt; results = movieLibrary.sort_all_movies_by_title_descending();<br /><br />
IEnumerable&lt;<span style="color: #0000ff">string</span>&gt; expected = <span style="color: #0000ff">new</span>[] 
<br />
{ 
<br />
theres_something_about_mary.title,<br />
the_ring.title,<br />
shrek.title,<br />
pirates_of_the_carribean.title,<br />
indiana_jones_and_the_temple_of_doom.title,<br />
cars.title,<br />
a_bugs_life.title<br />
};<br />
Assert.IsTrue(results.Select(m =&gt; m.title).SequenceEqual(expected));<br />
}</pre>
          <br />
        </div>
        <p>
thanks to <a href="http://stackoverflow.com/questions/5218505/assert-that-a-collection-is-in-the-right-order">http://stackoverflow.com/questions/5218505/assert-that-a-collection-is-in-the-right-order</a></p>
        <img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=b3fe2704-ba3a-4437-b5de-db01edb19358" />
      </body>
      <title>Asserting order of a Collection</title>
      <guid isPermaLink="false">http://www.programgood.net/PermaLink,guid,b3fe2704-ba3a-4437-b5de-db01edb19358.aspx</guid>
      <link>http://www.programgood.net/2011/03/07/AssertingOrderOfACollection.aspx</link>
      <pubDate>Mon, 07 Mar 2011 10:50:09 GMT</pubDate>
      <description>&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;[TestMethod]&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; when_sorting_movies_it_should_be_able_to_sort_all_movies_by_title_descending()&lt;br /&gt;
{&lt;br /&gt;
populateTestMovies(movie_collection);&lt;br /&gt;
MovieLibrary movieLibrary = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; MovieLibrary(movie_collection);&lt;br /&gt;
IEnumerable&amp;lt;Movie&amp;gt; results = movieLibrary.sort_all_movies_by_title_descending();&lt;br /&gt;
&lt;br /&gt;
IEnumerable&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt; expected = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt;[] 
&lt;br /&gt;
{ 
&lt;br /&gt;
theres_something_about_mary.title,&lt;br /&gt;
the_ring.title,&lt;br /&gt;
shrek.title,&lt;br /&gt;
pirates_of_the_carribean.title,&lt;br /&gt;
indiana_jones_and_the_temple_of_doom.title,&lt;br /&gt;
cars.title,&lt;br /&gt;
a_bugs_life.title&lt;br /&gt;
};&lt;br /&gt;
Assert.IsTrue(results.Select(m =&amp;gt; m.title).SequenceEqual(expected));&lt;br /&gt;
}&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
thanks to &lt;a href="http://stackoverflow.com/questions/5218505/assert-that-a-collection-is-in-the-right-order"&gt;http://stackoverflow.com/questions/5218505/assert-that-a-collection-is-in-the-right-order&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=b3fe2704-ba3a-4437-b5de-db01edb19358" /&gt;</description>
      <category>c# language</category>
      <category>Testing</category>
    </item>
    <item>
      <trackback:ping>http://www.programgood.net/Trackback.aspx?guid=8bb121bb-7e4d-4fb5-8985-a8965ecbdab6</trackback:ping>
      <pingback:server>http://www.programgood.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.programgood.net/PermaLink,guid,8bb121bb-7e4d-4fb5-8985-a8965ecbdab6.aspx</pingback:target>
      <dc:creator>Dave Mateer</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <div>
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">[TestMethod]<br /><span style="color: #0000ff">public</span><span style="color: #0000ff">void</span> when_adding_two_different_copies_of_the_same_movie_it_should_store_only_1_copy_in_the_collection()<br />
{<br />
MovieLibrary movieLibrary = <span style="color: #0000ff">new</span> MovieLibrary(movie_collection);<br />
Movie speed_racer = <span style="color: #0000ff">new</span> Movie { title = <span style="color: #006080">"Speed
Racer"</span> };<br />
Movie another_copy_of_speed_racer = <span style="color: #0000ff">new</span> Movie
{ title = <span style="color: #006080">"Speed Racer"</span> };<br /><br />
movieLibrary.add(speed_racer);<br />
movieLibrary.add(another_copy_of_speed_racer);<br /><br />
Assert.AreEqual(1, movie_collection.Count);<br />
}</pre>
        </div>
        <div> 
</div>
        <div>Here is MovieLibrary:
</div>
        <div id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <span style="color: #0000ff">public</span>
            <span style="color: #0000ff">void</span> add(Movie
movie)<br />
{<br /><span style="color: #008000">// .Contains is from List</span><br /><span style="color: #008000">// Actually uses .Equals method to see if any movies
in collection is .Equal to the new one</span><br /><span style="color: #0000ff">if</span> (!_list_of_movies_passed_to_us.Contains(movie))<br />
_list_of_movies_passed_to_us.Add(movie);<br />
}<br /></pre>
          <br />
        </div>
And here is Movie, with the shorter way commented out with a longer way working 
<div><br /></div><p></p><div id="codeSnippetWrapper"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">public</span><span style="color: #0000ff">class</span> Movie
: IEquatable&lt;Movie&gt;<br />
{<br /><span style="color: #008000">// Properties</span><br /><span style="color: #0000ff">public</span><span style="color: #0000ff">string</span> title
{ get; set; }<br /><span style="color: #0000ff">public</span> ProductionStudio production_studio { get;
set; }<br /><span style="color: #0000ff">public</span> Genre genre { get; set; }<br /><span style="color: #0000ff">public</span><span style="color: #0000ff">int</span> rating
{ get; set; }<br /><span style="color: #0000ff">public</span> DateTime date_published { get; set; }<br /><br /><span style="color: #008000">// Method</span><br /><span style="color: #0000ff">public</span><span style="color: #0000ff">bool</span> Equals(Movie
other)<br />
{<br /><span style="color: #008000">//return other == null ? false : other.title == this.title;</span><br /><span style="color: #0000ff">if</span> (other == <span style="color: #0000ff">null</span>)<br /><span style="color: #0000ff">return</span><span style="color: #0000ff">false</span>;<br /><span style="color: #0000ff">else</span><span style="color: #0000ff">if</span> (other.title
== <span style="color: #0000ff">this</span>.title)<br /><span style="color: #0000ff">return</span><span style="color: #0000ff">true</span>;<br /><span style="color: #0000ff">else</span><br /><span style="color: #0000ff">return</span><span style="color: #0000ff">false</span>;<br />
}<br />
}<br /></pre><br /></div><img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=8bb121bb-7e4d-4fb5-8985-a8965ecbdab6" /></body>
      <title>IEquatable</title>
      <guid isPermaLink="false">http://www.programgood.net/PermaLink,guid,8bb121bb-7e4d-4fb5-8985-a8965ecbdab6.aspx</guid>
      <link>http://www.programgood.net/2011/03/07/IEquatable.aspx</link>
      <pubDate>Mon, 07 Mar 2011 10:48:47 GMT</pubDate>
      <description>&lt;div&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;[TestMethod]&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; when_adding_two_different_copies_of_the_same_movie_it_should_store_only_1_copy_in_the_collection()&lt;br /&gt;
{&lt;br /&gt;
MovieLibrary movieLibrary = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; MovieLibrary(movie_collection);&lt;br /&gt;
Movie speed_racer = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Movie { title = &lt;span style="color: #006080"&gt;&amp;quot;Speed
Racer&amp;quot;&lt;/span&gt; };&lt;br /&gt;
Movie another_copy_of_speed_racer = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Movie
{ title = &lt;span style="color: #006080"&gt;&amp;quot;Speed Racer&amp;quot;&lt;/span&gt; };&lt;br /&gt;
&lt;br /&gt;
movieLibrary.add(speed_racer);&lt;br /&gt;
movieLibrary.add(another_copy_of_speed_racer);&lt;br /&gt;
&lt;br /&gt;
Assert.AreEqual(1, movie_collection.Count);&lt;br /&gt;
}&lt;/pre&gt;
&lt;/div&gt;
&lt;div&gt;&amp;#160;
&lt;/div&gt;
&lt;div&gt;Here is MovieLibrary:
&lt;/div&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; add(Movie
movie)&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #008000"&gt;// .Contains is from List&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;// Actually uses .Equals method to see if any movies
in collection is .Equal to the new one&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!_list_of_movies_passed_to_us.Contains(movie))&lt;br /&gt;
_list_of_movies_passed_to_us.Add(movie);&lt;br /&gt;
}&lt;br /&gt;
&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
And here is Movie, with the shorter way commented out with a longer way working 
&lt;div&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Movie
: IEquatable&amp;lt;Movie&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #008000"&gt;// Properties&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; title
{ get; set; }&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; ProductionStudio production_studio { get;
set; }&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; Genre genre { get; set; }&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; rating
{ get; set; }&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; DateTime date_published { get; set; }&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;// Method&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; Equals(Movie
other)&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #008000"&gt;//return other == null ? false : other.title == this.title;&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (other == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;else&lt;/span&gt; &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (other.title
== &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.title)&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;else&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;;&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=8bb121bb-7e4d-4fb5-8985-a8965ecbdab6" /&gt;</description>
      <category>c# language</category>
      <category>MovieLib</category>
    </item>
    <item>
      <trackback:ping>http://www.programgood.net/Trackback.aspx?guid=5e73381c-0eb5-4127-9e70-851555c34046</trackback:ping>
      <pingback:server>http://www.programgood.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.programgood.net/PermaLink,guid,5e73381c-0eb5-4127-9e70-851555c34046.aspx</pingback:target>
      <dc:creator>Dave Mateer</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="http://stackoverflow.com/questions/3686739/what-does-return-type-of-icollectionperson-mean">http://stackoverflow.com/questions/3686739/what-does-return-type-of-icollectionperson-mean</a>
        </p>
        <p>
It is often better to return an interface instead of ‘concrete’ class (or implementation).
</p>
        <p>
The reason for this is the freedom it provides – the implementation may change at
a later date without affecting the calling code.
</p>
        <p>
eg giveMeAllThings can change internally as long as I implement the methods that ICollection
requires.  And as a List implements these (and more), then this works.
</p>
        <p>
Inside giveMeAllThings, I could have anything I like (doesn’t have to be a List).
</p>
        <div id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <span style="color: #0000ff">public</span>
            <span style="color: #0000ff">class</span> Thing<br />
{<br /><span style="color: #0000ff">public</span><span style="color: #0000ff">string</span> name
{ get; set; }<br /><span style="color: #0000ff">public</span><span style="color: #0000ff">int</span> age
{ get; set; }<br /><br /><span style="color: #0000ff">public</span> ICollection&lt;Thing&gt; giveMeAllThings() 
<br />
{<br />
IList&lt;Thing&gt; listOfThings = <span style="color: #0000ff">new</span> List&lt;Thing&gt;();<br />
Thing thing1 = <span style="color: #0000ff">new</span> Thing { name = <span style="color: #006080">"phone"</span>,
age = 3 };<br />
Thing thing2 = <span style="color: #0000ff">new</span> Thing { name = <span style="color: #006080">"waterbottle"</span>,
age = 2 };<br />
Thing thing3 = <span style="color: #0000ff">new</span> Thing { name = <span style="color: #006080">"pinecone"</span>,
age = 17 };<br />
listOfThings.Add(thing1);<br />
listOfThings.Add(thing2);<br />
listOfThings.Add(thing3);<br /><span style="color: #008000">//foreach (Thing t in listOfThings)</span><br /><span style="color: #008000">// yield return t;</span><br /><br /><span style="color: #0000ff">return</span> listOfThings;<br />
}<br />
}<br /><br />
[TestClass]<br /><span style="color: #0000ff">public</span><span style="color: #0000ff">class</span> UnitTest1<br />
{<br />
[TestMethod]<br /><span style="color: #0000ff">public</span><span style="color: #0000ff">void</span> UnitTestThings()<br />
{<br />
Thing thing = <span style="color: #0000ff">new</span> Thing();<br />
IEnumerable&lt;Thing&gt; listOfThings = thing.giveMeAllThings(); 
<br />
Assert.AreEqual(3, listOfThings.Count()); <span style="color: #008000">// linq count</span><br />
Assert.IsTrue(listOfThings.Any(t =&gt; t.name == <span style="color: #006080">"phone"</span> &amp;&amp;
t.age == 3));<br />
Assert.IsTrue(listOfThings.Any(t =&gt; t.name == <span style="color: #006080">"waterbottle"</span> &amp;&amp;
t.age == 2));<br />
Assert.IsTrue(listOfThings.Any(t =&gt; t.name == <span style="color: #006080">"pinecone"</span> &amp;&amp;
t.age == 17));<br />
}<br /><br />
[TestMethod]<br /><span style="color: #0000ff">public</span><span style="color: #0000ff">void</span> UnitTestThingsWhereNeedAnICollection()<br />
{<br />
Thing thing = <span style="color: #0000ff">new</span> Thing();<br />
ICollection&lt;Thing&gt; listOfThings = thing.giveMeAllThings();<br />
Assert.AreEqual(3, listOfThings.Count); <span style="color: #008000">// ICollection
count</span><br />
}<br /><br /><span style="color: #008000">// Won't compile as return type of giveMeAllThings is
an ICollection</span><br /><span style="color: #008000">//[TestMethod]</span><br /><span style="color: #008000">//public void UnitTestThingsWhereINeedAnActualList()</span><br /><span style="color: #008000">//{</span><br /><span style="color: #008000">// Thing thing = new Thing();</span><br /><span style="color: #008000">// IList&lt;Thing&gt; listOfThings = thing.giveMeAllThings();</span><br /><span style="color: #008000">// Assert.AreEqual(3, listOfThings.Count); // List count</span><br />
//}</pre>
          <br />
        </div>
        <p>
 
</p>
        <p>
 <a href="http://elegantcode.com/2008/04/07/replace-your-collections-with-ienumerablet/">http://elegantcode.com/2008/04/07/replace-your-collections-with-ienumerablet/</a></p>
        <p>
Good article here.. basically saying that he is using IEnumerable&lt;T&gt; mostly,
and Linq for things like Count, ElementAt etc..
</p>
        <img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=5e73381c-0eb5-4127-9e70-851555c34046" />
      </body>
      <title>Returning an Interface IEnumerable, ICollection, IList</title>
      <guid isPermaLink="false">http://www.programgood.net/PermaLink,guid,5e73381c-0eb5-4127-9e70-851555c34046.aspx</guid>
      <link>http://www.programgood.net/2011/03/07/ReturningAnInterfaceIEnumerableICollectionIList.aspx</link>
      <pubDate>Mon, 07 Mar 2011 10:13:41 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a href="http://stackoverflow.com/questions/3686739/what-does-return-type-of-icollectionperson-mean"&gt;http://stackoverflow.com/questions/3686739/what-does-return-type-of-icollectionperson-mean&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
It is often better to return an interface instead of ‘concrete’ class (or implementation).
&lt;/p&gt;
&lt;p&gt;
The reason for this is the freedom it provides – the implementation may change at
a later date without affecting the calling code.
&lt;/p&gt;
&lt;p&gt;
eg giveMeAllThings can change internally as long as I implement the methods that ICollection
requires.&amp;#160; And as a List implements these (and more), then this works.
&lt;/p&gt;
&lt;p&gt;
Inside giveMeAllThings, I could have anything I like (doesn’t have to be a List).
&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Thing&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; name
{ get; set; }&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; age
{ get; set; }&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; ICollection&amp;lt;Thing&amp;gt; giveMeAllThings() 
&lt;br /&gt;
{&lt;br /&gt;
IList&amp;lt;Thing&amp;gt; listOfThings = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; List&amp;lt;Thing&amp;gt;();&lt;br /&gt;
Thing thing1 = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Thing { name = &lt;span style="color: #006080"&gt;&amp;quot;phone&amp;quot;&lt;/span&gt;,
age = 3 };&lt;br /&gt;
Thing thing2 = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Thing { name = &lt;span style="color: #006080"&gt;&amp;quot;waterbottle&amp;quot;&lt;/span&gt;,
age = 2 };&lt;br /&gt;
Thing thing3 = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Thing { name = &lt;span style="color: #006080"&gt;&amp;quot;pinecone&amp;quot;&lt;/span&gt;,
age = 17 };&lt;br /&gt;
listOfThings.Add(thing1);&lt;br /&gt;
listOfThings.Add(thing2);&lt;br /&gt;
listOfThings.Add(thing3);&lt;br /&gt;
&lt;span style="color: #008000"&gt;//foreach (Thing t in listOfThings)&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;// yield return t;&lt;/span&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;return&lt;/span&gt; listOfThings;&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
[TestClass]&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; UnitTest1&lt;br /&gt;
{&lt;br /&gt;
[TestMethod]&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; UnitTestThings()&lt;br /&gt;
{&lt;br /&gt;
Thing thing = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Thing();&lt;br /&gt;
IEnumerable&amp;lt;Thing&amp;gt; listOfThings = thing.giveMeAllThings(); 
&lt;br /&gt;
Assert.AreEqual(3, listOfThings.Count()); &lt;span style="color: #008000"&gt;// linq count&lt;/span&gt;
&lt;br /&gt;
Assert.IsTrue(listOfThings.Any(t =&amp;gt; t.name == &lt;span style="color: #006080"&gt;&amp;quot;phone&amp;quot;&lt;/span&gt; &amp;amp;&amp;amp;
t.age == 3));&lt;br /&gt;
Assert.IsTrue(listOfThings.Any(t =&amp;gt; t.name == &lt;span style="color: #006080"&gt;&amp;quot;waterbottle&amp;quot;&lt;/span&gt; &amp;amp;&amp;amp;
t.age == 2));&lt;br /&gt;
Assert.IsTrue(listOfThings.Any(t =&amp;gt; t.name == &lt;span style="color: #006080"&gt;&amp;quot;pinecone&amp;quot;&lt;/span&gt; &amp;amp;&amp;amp;
t.age == 17));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
[TestMethod]&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; UnitTestThingsWhereNeedAnICollection()&lt;br /&gt;
{&lt;br /&gt;
Thing thing = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Thing();&lt;br /&gt;
ICollection&amp;lt;Thing&amp;gt; listOfThings = thing.giveMeAllThings();&lt;br /&gt;
Assert.AreEqual(3, listOfThings.Count); &lt;span style="color: #008000"&gt;// ICollection
count&lt;/span&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;// Won't compile as return type of giveMeAllThings is
an ICollection&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;//[TestMethod]&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;//public void UnitTestThingsWhereINeedAnActualList()&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;//{&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;// Thing thing = new Thing();&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;// IList&amp;lt;Thing&amp;gt; listOfThings = thing.giveMeAllThings();&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;// Assert.AreEqual(3, listOfThings.Count); // List count&lt;/span&gt;
&lt;br /&gt;
//}&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
&amp;#160;&lt;a href="http://elegantcode.com/2008/04/07/replace-your-collections-with-ienumerablet/"&gt;http://elegantcode.com/2008/04/07/replace-your-collections-with-ienumerablet/&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Good article here.. basically saying that he is using IEnumerable&amp;lt;T&amp;gt; mostly,
and Linq for things like Count, ElementAt etc..
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=5e73381c-0eb5-4127-9e70-851555c34046" /&gt;</description>
      <category>c# language</category>
    </item>
    <item>
      <trackback:ping>http://www.programgood.net/Trackback.aspx?guid=1bdbbe7b-7f94-427c-a90f-e4be060f9150</trackback:ping>
      <pingback:server>http://www.programgood.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.programgood.net/PermaLink,guid,1bdbbe7b-7f94-427c-a90f-e4be060f9150.aspx</pingback:target>
      <dc:creator>Dave Mateer</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
From <a href="http://msdn.microsoft.com/en-us/library/ms173156.aspx">http://msdn.microsoft.com/en-us/library/ms173156.aspx</a></p>
        <div id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <span style="color: #0000ff">public</span>
            <span style="color: #0000ff">class</span> Car
: IEquatable&lt;Car&gt;<br />
{<br /><span style="color: #0000ff">public</span><span style="color: #0000ff">string</span> Make
{get; set;}<br /><span style="color: #0000ff">public</span><span style="color: #0000ff">string</span> Model
{ get; set; }<br /><span style="color: #0000ff">public</span><span style="color: #0000ff">string</span> Year
{ get; set; }<br /><br /><span style="color: #008000">// Implementation of IEquatable&lt;T&gt; interface</span><br /><span style="color: #0000ff">public</span><span style="color: #0000ff">bool</span> Equals(Car
car)<br />
{<br /><span style="color: #0000ff">if</span> (<span style="color: #0000ff">this</span>.Make
== car.Make &amp;&amp;<br /><span style="color: #0000ff">this</span>.Model == car.Model &amp;&amp;<br /><span style="color: #0000ff">this</span>.Year == car.Year)<br />
{<br /><span style="color: #0000ff">return</span><span style="color: #0000ff">true</span>;<br />
}<br /><span style="color: #0000ff">else</span><br /><span style="color: #0000ff">return</span><span style="color: #0000ff">false</span>;<br />
}<br />
}</pre>
          <br />
        </div>
        <p>
When a class implements an interface, the class provides an implementation for all
the members (properties and methods) defined by the interface
</p>
        <p>
The <a href="http://msdn.microsoft.com/en-us/library/ms131187.aspx">IEquatable&lt;T&gt;</a> interface
announces to the user of the object that the object can determine whether it is equal
to other objects of the same type, and the user of the interface does not have to
know how this is implemented.
</p>
        <p>
          <a href="http://www.devarticles.com/c/a/C-Sharp/Interface-IEnumerable-and-IEnumerator-in-C-sharp/1/">http://www.devarticles.com/c/a/C-Sharp/Interface-IEnumerable-and-IEnumerator-in-C-sharp/1/</a>
        </p>
        <p>
What is an interface? 
<br />
"An interface is a collection of method definitions (without implementations)
and constant values". 
</p>
        <p>
Its purpose is to captures similarities between unrelated classes without forcing
a class relationship,
</p>
        <p>
IEnumerable and IEnumerator are the best interface examples there are for you to understand
the role of interface. Classes implementing these two interfaces are classified as
an enumerable collection. This means that class behaves like any other collection
object written by Microsoft, such as an ArrayList. 
</p>
        <p>
There are many features that define an enumerable collection, and by implementing
these two interfaces, the framework guarantees that this object has these features.
For example, an enumerable collection must have a method called MoveNext, which moves
the cursor within the collection one step forward. By implementing the IEnumerator
interface, the class is promising (and is required) to implement this method. 
</p>
        <p>
As mentioned above, when a class implements these interfaces and is defined as an
enumerable collection, it behaves like one as well. This means that it is capable
of being iterated using a foreach statement, just like we can do with an ArrayList
object. 
</p>
        <h5>Programming to an Interface
</h5>
        <p>
          <a href="http://stackoverflow.com/questions/383947/what-does-it-mean-to-program-to-an-interface">http://stackoverflow.com/questions/383947/what-does-it-mean-to-program-to-an-interface</a>
        </p>
        <p>
common traits or behaviors that were exhibited by potentially many non-related classes
of objects
</p>
        <img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=1bdbbe7b-7f94-427c-a90f-e4be060f9150" />
      </body>
      <title>Implementing an Interface</title>
      <guid isPermaLink="false">http://www.programgood.net/PermaLink,guid,1bdbbe7b-7f94-427c-a90f-e4be060f9150.aspx</guid>
      <link>http://www.programgood.net/2011/03/04/ImplementingAnInterface.aspx</link>
      <pubDate>Fri, 04 Mar 2011 18:44:42 GMT</pubDate>
      <description>&lt;p&gt;
From &lt;a href="http://msdn.microsoft.com/en-us/library/ms173156.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms173156.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Car
: IEquatable&amp;lt;Car&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; Make
{get; set;}&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; Model
{ get; set; }&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; Year
{ get; set; }&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;// Implementation of IEquatable&amp;lt;T&amp;gt; interface&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; Equals(Car
car)&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.Make
== car.Make &amp;amp;&amp;amp;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.Model == car.Model &amp;amp;&amp;amp;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.Year == car.Year)&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;;&lt;br /&gt;
}&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;else&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;;&lt;br /&gt;
}&lt;br /&gt;
}&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
When a class implements an interface, the class provides an implementation for all
the members (properties and methods) defined by the interface
&lt;/p&gt;
&lt;p&gt;
The &lt;a href="http://msdn.microsoft.com/en-us/library/ms131187.aspx"&gt;IEquatable&amp;lt;T&amp;gt;&lt;/a&gt; interface
announces to the user of the object that the object can determine whether it is equal
to other objects of the same type, and the user of the interface does not have to
know how this is implemented.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.devarticles.com/c/a/C-Sharp/Interface-IEnumerable-and-IEnumerator-in-C-sharp/1/"&gt;http://www.devarticles.com/c/a/C-Sharp/Interface-IEnumerable-and-IEnumerator-in-C-sharp/1/&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
What is an interface? 
&lt;br /&gt;
&amp;quot;An interface is a collection of method definitions (without implementations)
and constant values&amp;quot;. 
&lt;/p&gt;
&lt;p&gt;
Its purpose is to captures similarities between unrelated classes without forcing
a class relationship,
&lt;/p&gt;
&lt;p&gt;
IEnumerable and IEnumerator are the best interface examples there are for you to understand
the role of interface. Classes implementing these two interfaces are classified as
an enumerable collection. This means that class behaves like any other collection
object written by Microsoft, such as an ArrayList. 
&lt;/p&gt;
&lt;p&gt;
There are many features that define an enumerable collection, and by implementing
these two interfaces, the framework guarantees that this object has these features.
For example, an enumerable collection must have a method called MoveNext, which moves
the cursor within the collection one step forward. By implementing the IEnumerator
interface, the class is promising (and is required) to implement this method. 
&lt;/p&gt;
&lt;p&gt;
As mentioned above, when a class implements these interfaces and is defined as an
enumerable collection, it behaves like one as well. This means that it is capable
of being iterated using a foreach statement, just like we can do with an ArrayList
object. 
&lt;/p&gt;
&lt;h5&gt;Programming to an Interface
&lt;/h5&gt;
&lt;p&gt;
&lt;a href="http://stackoverflow.com/questions/383947/what-does-it-mean-to-program-to-an-interface"&gt;http://stackoverflow.com/questions/383947/what-does-it-mean-to-program-to-an-interface&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
common traits or behaviors that were exhibited by potentially many non-related classes
of objects
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=1bdbbe7b-7f94-427c-a90f-e4be060f9150" /&gt;</description>
      <category>c# language</category>
    </item>
    <item>
      <trackback:ping>http://www.programgood.net/Trackback.aspx?guid=b02ca926-0007-4342-a2ce-09155f5fddbf</trackback:ping>
      <pingback:server>http://www.programgood.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.programgood.net/PermaLink,guid,b02ca926-0007-4342-a2ce-09155f5fddbf.aspx</pingback:target>
      <dc:creator>Dave Mateer</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
“..enums a great way to declare a variable of a type that can be one of a fixed set
of values.”
</p>
        <p>
          <a href="http://geekswithblogs.net/BlackRabbitCoder/archive/2010/07/08/c-fundamentals-the-joys-and-pitfalls-of-enums.aspx">http://geekswithblogs.net/BlackRabbitCoder/archive/2010/07/08/c-fundamentals-the-joys-and-pitfalls-of-enums.aspx</a>
        </p>
        <div id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <span style="color: #0000ff">public</span>
            <span style="color: #0000ff">enum</span> ProductionStudio
{ MGM, Paramount, Universal, Pixar, Disney, Dreamworks};<br /><br /><br /><span style="color: #0000ff">public</span><span style="color: #0000ff">class</span> ProductionStudio<br />
{<br /><span style="color: #0000ff">public</span><span style="color: #0000ff">static</span><span style="color: #0000ff">readonly</span> ProductionStudio
MGM = <span style="color: #0000ff">new</span> ProductionStudio();<br /><span style="color: #0000ff">public</span><span style="color: #0000ff">static</span><span style="color: #0000ff">readonly</span> ProductionStudio
Paramount = <span style="color: #0000ff">new</span> ProductionStudio();<br /><span style="color: #0000ff">public</span><span style="color: #0000ff">static</span><span style="color: #0000ff">readonly</span> ProductionStudio
Universal = <span style="color: #0000ff">new</span> ProductionStudio();<br /><span style="color: #0000ff">public</span><span style="color: #0000ff">static</span><span style="color: #0000ff">readonly</span> ProductionStudio
Pixar = <span style="color: #0000ff">new</span> ProductionStudio();<br /><span style="color: #0000ff">public</span><span style="color: #0000ff">static</span><span style="color: #0000ff">readonly</span> ProductionStudio
Disney = <span style="color: #0000ff">new</span> ProductionStudio();<br /><span style="color: #0000ff">public</span><span style="color: #0000ff">static</span><span style="color: #0000ff">readonly</span> ProductionStudio
Dreamworks = <span style="color: #0000ff">new</span> ProductionStudio();<br />
}</pre>
          <br />
        </div>
        <p>
In some situations you may want to use public static readonly… a constant really. 
Gives intellisense.
</p>
        <img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=b02ca926-0007-4342-a2ce-09155f5fddbf" />
      </body>
      <title>Enums and Public Static Readonly</title>
      <guid isPermaLink="false">http://www.programgood.net/PermaLink,guid,b02ca926-0007-4342-a2ce-09155f5fddbf.aspx</guid>
      <link>http://www.programgood.net/2011/03/03/EnumsAndPublicStaticReadonly.aspx</link>
      <pubDate>Thu, 03 Mar 2011 21:13:20 GMT</pubDate>
      <description>&lt;p&gt;
“..enums a great way to declare a variable of a type that can be one of a fixed set
of values.”
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://geekswithblogs.net/BlackRabbitCoder/archive/2010/07/08/c-fundamentals-the-joys-and-pitfalls-of-enums.aspx"&gt;http://geekswithblogs.net/BlackRabbitCoder/archive/2010/07/08/c-fundamentals-the-joys-and-pitfalls-of-enums.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;enum&lt;/span&gt; ProductionStudio
{ MGM, Paramount, Universal, Pixar, Disney, Dreamworks};&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; ProductionStudio&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;readonly&lt;/span&gt; ProductionStudio
MGM = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ProductionStudio();&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;readonly&lt;/span&gt; ProductionStudio
Paramount = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ProductionStudio();&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;readonly&lt;/span&gt; ProductionStudio
Universal = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ProductionStudio();&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;readonly&lt;/span&gt; ProductionStudio
Pixar = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ProductionStudio();&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;readonly&lt;/span&gt; ProductionStudio
Disney = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ProductionStudio();&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;readonly&lt;/span&gt; ProductionStudio
Dreamworks = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ProductionStudio();&lt;br /&gt;
}&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
In some situations you may want to use public static readonly… a constant really.&amp;#160;
Gives intellisense.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=b02ca926-0007-4342-a2ce-09155f5fddbf" /&gt;</description>
      <category>c# language</category>
    </item>
    <item>
      <trackback:ping>http://www.programgood.net/Trackback.aspx?guid=65a2c440-6b5b-415e-aca1-3f5428c5ae5c</trackback:ping>
      <pingback:server>http://www.programgood.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.programgood.net/PermaLink,guid,65a2c440-6b5b-415e-aca1-3f5428c5ae5c.aspx</pingback:target>
      <dc:creator>Dave Mateer</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="http://stackoverflow.com/questions/295104/what-is-the-difference-between-a-field-and-a-property-in-c">http://stackoverflow.com/questions/295104/what-is-the-difference-between-a-field-and-a-property-in-c</a>
        </p>
        <div id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <span style="color: #0000ff">public</span>
            <span style="color: #0000ff">class</span> Movie<br />
{<br /><span style="color: #008000">// this is a field. It is private to your class and stores
the actual data.</span><br /><span style="color: #0000ff">private</span><span style="color: #0000ff">string</span> _title;<br /><br /><span style="color: #008000">// this is a public field. Almost never used, as its
exposing the internals of the class to the outside world</span><br /><span style="color: #0000ff">public</span><span style="color: #0000ff">string</span> _title;<br /><br /><span style="color: #008000">// this is a property. When you access it uses the underlying
field, but only exposes</span><br /><span style="color: #008000">// the contract that will not be affected by the underlying
field</span><br /><span style="color: #0000ff">public</span><span style="color: #0000ff">string</span> Title<br />
{<br />
get<br />
{<br /><span style="color: #0000ff">return</span> _title;<br />
}<br />
set<br />
{<br />
_title = <span style="color: #0000ff">value</span>;<br />
}<br />
}<br /><br /><span style="color: #008000">// Auto implemented property in C#3</span><br /><span style="color: #0000ff">public</span><span style="color: #0000ff">string</span> Title1
{ get; set; } 
<br />
}</pre>
          <br />
        </div>
        <img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=65a2c440-6b5b-415e-aca1-3f5428c5ae5c" />
      </body>
      <title>Fields and Properties and AutoProperties</title>
      <guid isPermaLink="false">http://www.programgood.net/PermaLink,guid,65a2c440-6b5b-415e-aca1-3f5428c5ae5c.aspx</guid>
      <link>http://www.programgood.net/2011/03/03/FieldsAndPropertiesAndAutoProperties.aspx</link>
      <pubDate>Thu, 03 Mar 2011 20:44:31 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a href="http://stackoverflow.com/questions/295104/what-is-the-difference-between-a-field-and-a-property-in-c"&gt;http://stackoverflow.com/questions/295104/what-is-the-difference-between-a-field-and-a-property-in-c&lt;/a&gt;
&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Movie&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #008000"&gt;// this is a field. It is private to your class and stores
the actual data.&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; _title;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;// this is a public field. Almost never used, as its
exposing the internals of the class to the outside world&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; _title;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;// this is a property. When you access it uses the underlying
field, but only exposes&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;// the contract that will not be affected by the underlying
field&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; Title&lt;br /&gt;
{&lt;br /&gt;
get&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _title;&lt;br /&gt;
}&lt;br /&gt;
set&lt;br /&gt;
{&lt;br /&gt;
_title = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;;&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;// Auto implemented property in C#3&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; Title1
{ get; set; } 
&lt;br /&gt;
}&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=65a2c440-6b5b-415e-aca1-3f5428c5ae5c" /&gt;</description>
      <category>c# language</category>
    </item>
    <item>
      <trackback:ping>http://www.programgood.net/Trackback.aspx?guid=de6b417b-3f5c-49b2-b56b-fa5e3ffca780</trackback:ping>
      <pingback:server>http://www.programgood.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.programgood.net/PermaLink,guid,de6b417b-3f5c-49b2-b56b-fa5e3ffca780.aspx</pingback:target>
      <dc:creator>Dave Mateer</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="http://stackoverflow.com/questions/1859248/how-to-change-time-in-datetime">http://stackoverflow.com/questions/1859248/how-to-change-time-in-datetime</a>
        </p>
        <img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=de6b417b-3f5c-49b2-b56b-fa5e3ffca780" />
      </body>
      <title>Changing a Time in C#</title>
      <guid isPermaLink="false">http://www.programgood.net/PermaLink,guid,de6b417b-3f5c-49b2-b56b-fa5e3ffca780.aspx</guid>
      <link>http://www.programgood.net/2011/02/17/ChangingATimeInC.aspx</link>
      <pubDate>Thu, 17 Feb 2011 22:45:00 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a href="http://stackoverflow.com/questions/1859248/how-to-change-time-in-datetime"&gt;http://stackoverflow.com/questions/1859248/how-to-change-time-in-datetime&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=de6b417b-3f5c-49b2-b56b-fa5e3ffca780" /&gt;</description>
      <category>c# language</category>
      <category>DateTime</category>
    </item>
    <item>
      <trackback:ping>http://www.programgood.net/Trackback.aspx?guid=57993c48-4f55-40c4-8ba6-4a2138a38b2e</trackback:ping>
      <pingback:server>http://www.programgood.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.programgood.net/PermaLink,guid,57993c48-4f55-40c4-8ba6-4a2138a38b2e.aspx</pingback:target>
      <dc:creator>Dave Mateer</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="http://www.xiirus.net/articles/article-_net-convert-datetime-from-one-timezone-to-another-7e44y.aspx">http://www.xiirus.net/articles/article-_net-convert-datetime-from-one-timezone-to-another-7e44y.aspx</a>
        </p>
        <img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=57993c48-4f55-40c4-8ba6-4a2138a38b2e" />
      </body>
      <title>Coverting DateTimes to different TimeZones in .NET</title>
      <guid isPermaLink="false">http://www.programgood.net/PermaLink,guid,57993c48-4f55-40c4-8ba6-4a2138a38b2e.aspx</guid>
      <link>http://www.programgood.net/2011/02/17/CovertingDateTimesToDifferentTimeZonesInNET.aspx</link>
      <pubDate>Thu, 17 Feb 2011 22:26:22 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a href="http://www.xiirus.net/articles/article-_net-convert-datetime-from-one-timezone-to-another-7e44y.aspx"&gt;http://www.xiirus.net/articles/article-_net-convert-datetime-from-one-timezone-to-another-7e44y.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=57993c48-4f55-40c4-8ba6-4a2138a38b2e" /&gt;</description>
      <category>c# language</category>
      <category>DateTime</category>
    </item>
    <item>
      <trackback:ping>http://www.programgood.net/Trackback.aspx?guid=5972b679-3392-41a7-8fd6-69401bdaaa8b</trackback:ping>
      <pingback:server>http://www.programgood.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.programgood.net/PermaLink,guid,5972b679-3392-41a7-8fd6-69401bdaaa8b.aspx</pingback:target>
      <dc:creator>Dave Mateer</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
From the Guernsey adult literacy project, page 51.
</p>
        <p>
What arithmetical symbols do you have to insert in between the numbers to get the
correct result?
</p>
        <p>
1 3 5 7 9 = 3
</p>
        <p>
1 3 5 7 9 = 47
</p>
        <p>
1 3 5 7 9 = 18
</p>
        <p>
Note that only the symbols +, –, * and / are used.
</p>
        <p>
An interesting challenge – do they mean that operator precedence is invoked too? 
ie MIDAS – Multiply before divide before add before subtract?
</p>
        <p>
          <a href="http://msdn.microsoft.com/en-us/library/aa691323(v=vs.71).aspx">http://msdn.microsoft.com/en-us/library/aa691323(v=vs.71).aspx</a> 
- order of all operators
</p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/GuernseyChallenge_1462D/image_2.png">
            <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.programgood.net/content/binary/WindowsLiveWriter/GuernseyChallenge_1462D/image_thumb.png" width="271" height="159" />
          </a>
        </p>
        <p>
a very useful sanity check in google.. 
</p>
        <p>
 
</p>
        <p>
Answers I found are:
</p>
        <p>
-1-3+5-7+9 = (-1) - 3 + 5 - 7 + 9 = 3
</p>
        <p>
1+3*5-7+9 = 1 + (3 * 5) - 7 + 9 = 18 
<br />
-1*3+5+7+9 = 181 + (3 * 5) - 7 + 9 = 18 
</p>
        <p>
1*3+5*7+9 =  (1 * 3) + (5 * 7) + 9 = 47 
<br />
-1-3*5+7*9 =(-1) - (3 * 5) + (7 * 9) = 47
</p>
        <p>
Code I used is:
</p>
        <div id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <span style="color: #0000ff">string</span> opZ
= <span style="color: #006080">""</span>;<br /><span style="color: #0000ff">string</span> opA = <span style="color: #006080">""</span>;<br /><span style="color: #0000ff">string</span> opB = <span style="color: #006080">""</span>;<br /><span style="color: #0000ff">string</span> opC = <span style="color: #006080">""</span>;<br /><span style="color: #0000ff">string</span> opD = <span style="color: #006080">""</span>;<br /><span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> h
= 1; h &lt;= 2; h++) <span style="color: #008000">// making the first number positive
or negative</span><br />
{<br /><span style="color: #0000ff">if</span> (h == 1) opZ = <span style="color: #006080">""</span>;<br /><span style="color: #0000ff">if</span> (h == 2) opZ = <span style="color: #006080">"-"</span>;<br /><br /><span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> i
= 1; i &lt;= 4; i++)<br />
{<br /><span style="color: #0000ff">if</span> (i == 1) opA = <span style="color: #006080">"*"</span>;<br /><span style="color: #0000ff">if</span> (i == 2) opA = <span style="color: #006080">"/"</span>;<br /><span style="color: #0000ff">if</span> (i == 3) opA = <span style="color: #006080">"+"</span>;<br /><span style="color: #0000ff">if</span> (i == 4) opA = <span style="color: #006080">"-"</span>;<br /><span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> j
= 1; j &lt;= 4; j++)<br />
{<br /><span style="color: #0000ff">if</span> (j == 1) opB = <span style="color: #006080">"*"</span>;<br /><span style="color: #0000ff">if</span> (j == 2) opB = <span style="color: #006080">"/"</span>;<br /><span style="color: #0000ff">if</span> (j == 3) opB = <span style="color: #006080">"+"</span>;<br /><span style="color: #0000ff">if</span> (j == 4) opB = <span style="color: #006080">"-"</span>;<br /><span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> k
= 1; k &lt;= 4; k++)<br />
{<br /><span style="color: #0000ff">if</span> (k == 1) opC = <span style="color: #006080">"*"</span>;<br /><span style="color: #0000ff">if</span> (k == 2) opC = <span style="color: #006080">"/"</span>;<br /><span style="color: #0000ff">if</span> (k == 3) opC = <span style="color: #006080">"+"</span>;<br /><span style="color: #0000ff">if</span> (k == 4) opC = <span style="color: #006080">"-"</span>;<br /><span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> l
= 1; l &lt;= 4; l++)<br />
{<br /><span style="color: #0000ff">if</span> (l == 1) opD = <span style="color: #006080">"*"</span>;<br /><span style="color: #0000ff">if</span> (l == 2) opD = <span style="color: #006080">"/"</span>;<br /><span style="color: #0000ff">if</span> (l == 3) opD = <span style="color: #006080">"+"</span>;<br /><span style="color: #0000ff">if</span> (l == 4) opD = <span style="color: #006080">"-"</span>;<br /><span style="color: #0000ff">string</span> expression = opZ + 1 + opA + 3 + opB +
5 + opC + 7 + opD + 9;<br />
DataTable dummy = <span style="color: #0000ff">new</span> DataTable();<br /><span style="color: #0000ff">double</span> result = Convert.ToDouble(dummy.Compute(expression, <span style="color: #0000ff">string</span>.Empty));<br /><span style="color: #0000ff">if</span> (result == 3)<br />
Debug.WriteLine(expression + <span style="color: #006080">" = 3"</span>);<br /><br /><span style="color: #0000ff">if</span> (result == 47)<br />
Debug.WriteLine(expression + <span style="color: #006080">" = 47"</span>);<br /><br /><span style="color: #0000ff">if</span> (result == 18)<br />
Debug.WriteLine(expression + <span style="color: #006080">" = 18"</span>);<br /><br />
}<br />
}<br />
}<br />
}<br />
}</pre>
          <br />
        </div>
        <p>
thanks to <a href="http://stackoverflow.com/questions/174664/operators-as-strings">http://stackoverflow.com/questions/174664/operators-as-strings</a> for
the DataTable help.
</p>
        <p>
From <a href="http://stackoverflow.com/questions/4679056/code-smell-in-dynamic-expression">http://stackoverflow.com/questions/4679056/code-smell-in-dynamic-expression</a></p>
        <h3>TDD
</h3>
        <p>
To help in the refactoring I used tests to make sure I hadn’t broken anything:
</p>
        <div id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <span style="color: #0000ff">using</span> System;<br /><span style="color: #0000ff">using</span> System.Text;<br /><span style="color: #0000ff">using</span> System.Collections.Generic;<br /><span style="color: #0000ff">using</span> System.Linq;<br /><span style="color: #0000ff">using</span> Microsoft.VisualStudio.TestTools.UnitTesting;<br /><span style="color: #0000ff">using</span> System.Data;<br /><span style="color: #0000ff">using</span> System.Diagnostics;<br /><br /><span style="color: #0000ff">namespace</span> Guernsey1<br />
{<br /><span style="color: #008000">/// &lt;summary&gt;</span><br /><span style="color: #008000">/// What arithmetical symbols do you have to insert in
between the numbers to get the correct result?</span><br /><span style="color: #008000">/// 1 3 5 7 9 = 3</span><br /><span style="color: #008000">/// 1 3 5 7 9 = 47</span><br /><span style="color: #008000">/// 1 3 5 7 9 = 18</span><br /><span style="color: #008000">/// There may be more than one answer for each one.</span><br /><span style="color: #008000">/// &lt;/summary&gt;</span><br />
[TestClass]<br /><span style="color: #0000ff">public</span><span style="color: #0000ff">class</span> UnitTest1<br />
{<br />
[TestMethod]<br /><span style="color: #0000ff">public</span><span style="color: #0000ff">void</span> GetAnswersForResultIs3()<br />
{<br />
List&lt;<span style="color: #0000ff">string</span>&gt; listOfExpressions = findArithmeticSymbolsInNumericOrder13579ThatGivesThisResult(3);<br /><span style="color: #0000ff">foreach</span> (<span style="color: #0000ff">string</span> expression <span style="color: #0000ff">in</span> listOfExpressions)<br />
Assert.AreEqual(<span style="color: #006080">"-1-3+5-7+9"</span>, expression);<br />
}<br /><br />
[TestMethod]<br /><span style="color: #0000ff">public</span><span style="color: #0000ff">void</span> GetAnswersForResultIs47()<br />
{<br />
List&lt;<span style="color: #0000ff">string</span>&gt; listOfExpressions = findArithmeticSymbolsInNumericOrder13579ThatGivesThisResult(47);<br />
Assert.AreEqual(<span style="color: #0000ff">true</span>, listOfExpressions.Contains(<span style="color: #006080">"1*3+5*7+9"</span>));<br />
Assert.AreEqual(<span style="color: #0000ff">true</span>, listOfExpressions.Contains(<span style="color: #006080">"-1-3*5+7*9"</span>));<br />
}<br /><br />
[TestMethod]<br /><span style="color: #0000ff">public</span><span style="color: #0000ff">void</span> GetAnswersForResultIs18()<br />
{<br />
List&lt;<span style="color: #0000ff">string</span>&gt; listOfExpressions = findArithmeticSymbolsInNumericOrder13579ThatGivesThisResult(18);<br />
Assert.AreEqual(<span style="color: #0000ff">true</span>, listOfExpressions.Contains(<span style="color: #006080">"-1*3+5+7+9"</span>));<br />
Assert.AreEqual(<span style="color: #0000ff">true</span>, listOfExpressions.Contains(<span style="color: #006080">"1+3*5-7+9"</span>));<br />
}<br /><br /><br /><br /><span style="color: #0000ff">public</span> List&lt;<span style="color: #0000ff">string</span>&gt;
findArithmeticSymbolsInNumericOrder13579ThatGivesThisResult(<span style="color: #0000ff">int</span> resultExpected) <span style="color: #008000">//
Jons</span><br />
{<br />
List&lt;<span style="color: #0000ff">string</span>&gt; listOfExpressions = <span style="color: #0000ff">new</span> List&lt;<span style="color: #0000ff">string</span>&gt;();<br /><span style="color: #0000ff">string</span>[] prefixes = { <span style="color: #006080">""</span>, <span style="color: #006080">"-"</span> };<br /><span style="color: #0000ff">string</span>[] operators = { <span style="color: #006080">"*"</span>, <span style="color: #006080">"/"</span>, <span style="color: #006080">"+"</span>, <span style="color: #006080">"-"</span> };<br />
IEnumerable&lt;<span style="color: #0000ff">string</span>&gt; expressions = from prefix <span style="color: #0000ff">in</span> prefixes<br />
from opA <span style="color: #0000ff">in</span> operators<br />
from opB <span style="color: #0000ff">in</span> operators<br />
from opC <span style="color: #0000ff">in</span> operators<br />
from opD <span style="color: #0000ff">in</span> operators<br />
select prefix + 1 + opA + 3 + opB + 5 + opC + 7 + opD + 9;<br /><br /><span style="color: #0000ff">foreach</span> (<span style="color: #0000ff">string</span> expression <span style="color: #0000ff">in</span> expressions)<br />
{<br />
DataTable dummy = <span style="color: #0000ff">new</span> DataTable();<br /><span style="color: #0000ff">double</span> result = Convert.ToDouble(dummy.Compute(expression, <span style="color: #0000ff">string</span>.Empty));<br /><span style="color: #0000ff">if</span> (result == resultExpected)<br />
listOfExpressions.Add(expression);<br />
}<br /><span style="color: #0000ff">return</span> listOfExpressions;<br />
}<br /><br /><span style="color: #0000ff">public</span> List&lt;<span style="color: #0000ff">string</span>&gt;
findArithmeticSymbolsInNumericOrder13579ThatGivesThisResult(<span style="color: #0000ff">int</span> resultExpected) <span style="color: #008000">//
Cines</span><br />
{<br /><span style="color: #0000ff">string</span>[] prefixes = { <span style="color: #006080">""</span>, <span style="color: #006080">"-"</span> };<br /><span style="color: #0000ff">string</span>[] operators = { <span style="color: #006080">"*"</span>, <span style="color: #006080">"/"</span>, <span style="color: #006080">"+"</span>, <span style="color: #006080">"-"</span> };<br />
List&lt;<span style="color: #0000ff">string</span>&gt; listOfExpressions = <span style="color: #0000ff">new</span> List&lt;<span style="color: #0000ff">string</span>&gt;();<br /><span style="color: #0000ff">foreach</span> (<span style="color: #0000ff">string</span> opA <span style="color: #0000ff">in</span> operators)<br /><span style="color: #0000ff">foreach</span> (<span style="color: #0000ff">string</span> opB <span style="color: #0000ff">in</span> operators)<br /><span style="color: #0000ff">foreach</span> (<span style="color: #0000ff">string</span> opC <span style="color: #0000ff">in</span> operators)<br /><span style="color: #0000ff">foreach</span> (<span style="color: #0000ff">string</span> opD <span style="color: #0000ff">in</span> operators)<br /><span style="color: #0000ff">foreach</span> (<span style="color: #0000ff">string</span> prefix <span style="color: #0000ff">in</span> prefixes)<br />
{<br /><span style="color: #0000ff">string</span> expression = prefix + 1 + opA + 3 + opB
+ 5 + opC + 7 + opD + 9;<br />
DataTable dummy = <span style="color: #0000ff">new</span> DataTable();<br /><span style="color: #0000ff">double</span> result = Convert.ToDouble(dummy.Compute(expression, <span style="color: #0000ff">string</span>.Empty));<br /><span style="color: #0000ff">if</span> (result == resultExpected)<br />
listOfExpressions.Add(expression);<br />
}<br /><span style="color: #0000ff">return</span> listOfExpressions;<br />
}<br /><br /><br /><span style="color: #0000ff">public</span> List&lt;<span style="color: #0000ff">string</span>&gt;
findArithmeticSymbolsInNumericOrder13579ThatGivesThisResult(<span style="color: #0000ff">int</span> resultExpected) <span style="color: #008000">//
Anton1</span><br />
{<br />
List&lt;<span style="color: #0000ff">string</span>&gt; listOfExpressions = <span style="color: #0000ff">new</span> List&lt;<span style="color: #0000ff">string</span>&gt;();<br />
var calculator = <span style="color: #0000ff">new</span> DataTable();<br />
var operators = <span style="color: #006080">"*/+-"</span>;<br /><span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> i
= 0; i &lt; 0x200; ++i)<br />
{<br /><span style="color: #0000ff">string</span> expression = String.Format(<span style="color: #006080">"{0}1{1}3{2}5{3}7{4}9"</span>,<br />
(i &amp; 0x100) != 0 ? <span style="color: #006080">"-"</span> : <span style="color: #006080">""</span>,<br />
operators[(i &gt;&gt; 0) &amp; 3],<br />
operators[(i &gt;&gt; 2) &amp; 3],<br />
operators[(i &gt;&gt; 4) &amp; 3],<br />
operators[(i &gt;&gt; 6) &amp; 3]);<br /><br />
var result = calculator.Compute(expression, String.Empty);<br /><span style="color: #0000ff">if</span> (Convert.ToDouble(result) == resultExpected)<br />
listOfExpressions.Add(expression);<br />
}<br /><span style="color: #0000ff">return</span> listOfExpressions;<br />
}<br /><br /><span style="color: #0000ff">public</span> List&lt;<span style="color: #0000ff">string</span>&gt;
findArithmeticSymbolsInNumericOrder13579ThatGivesThisResult(<span style="color: #0000ff">int</span> resultExpected) <span style="color: #008000">//
Anton2 - not working yet.. how to get the listOfExpressions?</span><br />
{<br />
List&lt;<span style="color: #0000ff">string</span>&gt; listOfExpressions = <span style="color: #0000ff">new</span> List&lt;<span style="color: #0000ff">string</span>&gt;();<br />
var operators = <span style="color: #0000ff">new</span> Func&lt;<span style="color: #0000ff">int</span>, <span style="color: #0000ff">int</span>, <span style="color: #0000ff">int</span>&gt;[]
{<br />
(a, b) =&gt; a + b,<br />
(a, b) =&gt; a - b,<br />
(a, b) =&gt; a * b,<br />
(a, b) =&gt; a / b 
<br />
};<br /><br /><span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> i
= 0; i &lt; 0x200; ++i)<br />
{<br />
var stack = 0; <span style="color: #008000">// max stack depth is 2 because only 2
priorities</span><br />
var last = 0; <span style="color: #008000">// imitate + for lowest precedence</span><br />
var <span style="color: #0000ff">value</span> = (i &amp; 0x100) != 0 ? -1 : 1;<br /><br /><span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> j
= 0; j &lt; 5; ++j) <span style="color: #008000">// extra item to force last reduction</span><br />
{<br />
var oper = (i &gt;&gt; j * 2) &amp; 3; <span style="color: #008000">// "input"
operator</span><br /><span style="color: #0000ff">if</span> (oper / 2 &lt;= last / 2) <span style="color: #008000">//
reduce?</span><br />
{<br />
stack = operators[last](stack, <span style="color: #0000ff">value</span>);<br />
}<br /><span style="color: #0000ff">else</span><span style="color: #008000">// stack is
empty; prepare to shift</span><br />
stack = <span style="color: #0000ff">value</span>;<br /><br /><span style="color: #0000ff">if</span> (j == 4) <span style="color: #0000ff">break</span>;<br /><br />
last = oper; <span style="color: #008000">// shift operator</span><br /><span style="color: #0000ff">value</span> = 3 + j * 2; <span style="color: #008000">//
"input" number</span><br />
}<br />
}<br /><span style="color: #008000">// result in stack</span><br /><br /><span style="color: #0000ff">return</span> listOfExpressions;<br />
}<br />
}<br />
}</pre>
          <br />
        </div>
        <img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=5972b679-3392-41a7-8fd6-69401bdaaa8b" />
      </body>
      <title>Dynamic Operators – Guernsey challenge</title>
      <guid isPermaLink="false">http://www.programgood.net/PermaLink,guid,5972b679-3392-41a7-8fd6-69401bdaaa8b.aspx</guid>
      <link>http://www.programgood.net/2011/01/13/DynamicOperatorsGuernseyChallenge.aspx</link>
      <pubDate>Thu, 13 Jan 2011 10:27:55 GMT</pubDate>
      <description>&lt;p&gt;
From the Guernsey adult literacy project, page 51.
&lt;/p&gt;
&lt;p&gt;
What arithmetical symbols do you have to insert in between the numbers to get the
correct result?
&lt;/p&gt;
&lt;p&gt;
1 3 5 7 9 = 3
&lt;/p&gt;
&lt;p&gt;
1 3 5 7 9 = 47
&lt;/p&gt;
&lt;p&gt;
1 3 5 7 9 = 18
&lt;/p&gt;
&lt;p&gt;
Note that only the symbols +, –, * and / are used.
&lt;/p&gt;
&lt;p&gt;
An interesting challenge – do they mean that operator precedence is invoked too?&amp;#160;
ie MIDAS – Multiply before divide before add before subtract?
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://msdn.microsoft.com/en-us/library/aa691323(v=vs.71).aspx"&gt;http://msdn.microsoft.com/en-us/library/aa691323(v=vs.71).aspx&lt;/a&gt;&amp;#160;
- order of all operators
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/GuernseyChallenge_1462D/image_2.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.programgood.net/content/binary/WindowsLiveWriter/GuernseyChallenge_1462D/image_thumb.png" width="271" height="159" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
a very useful sanity check in google.. 
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
Answers I found are:
&lt;/p&gt;
&lt;p&gt;
-1-3+5-7+9 = (-1) - 3 + 5 - 7 + 9 = 3
&lt;/p&gt;
&lt;p&gt;
1+3*5-7+9 = 1 + (3 * 5) - 7 + 9 = 18 
&lt;br /&gt;
-1*3+5+7+9 = 181 + (3 * 5) - 7 + 9 = 18 
&lt;/p&gt;
&lt;p&gt;
1*3+5*7+9 =&amp;#160; (1 * 3) + (5 * 7) + 9 = 47 
&lt;br /&gt;
-1-3*5+7*9 =(-1) - (3 * 5) + (7 * 9) = 47
&lt;/p&gt;
&lt;p&gt;
Code I used is:
&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; opZ
= &lt;span style="color: #006080"&gt;&amp;quot;&amp;quot;&lt;/span&gt;;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; opA = &lt;span style="color: #006080"&gt;&amp;quot;&amp;quot;&lt;/span&gt;;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; opB = &lt;span style="color: #006080"&gt;&amp;quot;&amp;quot;&lt;/span&gt;;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; opC = &lt;span style="color: #006080"&gt;&amp;quot;&amp;quot;&lt;/span&gt;;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; opD = &lt;span style="color: #006080"&gt;&amp;quot;&amp;quot;&lt;/span&gt;;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;for&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; h
= 1; h &amp;lt;= 2; h++) &lt;span style="color: #008000"&gt;// making the first number positive
or negative&lt;/span&gt;
&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (h == 1) opZ = &lt;span style="color: #006080"&gt;&amp;quot;&amp;quot;&lt;/span&gt;;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (h == 2) opZ = &lt;span style="color: #006080"&gt;&amp;quot;-&amp;quot;&lt;/span&gt;;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;for&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; i
= 1; i &amp;lt;= 4; i++)&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (i == 1) opA = &lt;span style="color: #006080"&gt;&amp;quot;*&amp;quot;&lt;/span&gt;;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (i == 2) opA = &lt;span style="color: #006080"&gt;&amp;quot;/&amp;quot;&lt;/span&gt;;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (i == 3) opA = &lt;span style="color: #006080"&gt;&amp;quot;+&amp;quot;&lt;/span&gt;;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (i == 4) opA = &lt;span style="color: #006080"&gt;&amp;quot;-&amp;quot;&lt;/span&gt;;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;for&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; j
= 1; j &amp;lt;= 4; j++)&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (j == 1) opB = &lt;span style="color: #006080"&gt;&amp;quot;*&amp;quot;&lt;/span&gt;;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (j == 2) opB = &lt;span style="color: #006080"&gt;&amp;quot;/&amp;quot;&lt;/span&gt;;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (j == 3) opB = &lt;span style="color: #006080"&gt;&amp;quot;+&amp;quot;&lt;/span&gt;;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (j == 4) opB = &lt;span style="color: #006080"&gt;&amp;quot;-&amp;quot;&lt;/span&gt;;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;for&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; k
= 1; k &amp;lt;= 4; k++)&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (k == 1) opC = &lt;span style="color: #006080"&gt;&amp;quot;*&amp;quot;&lt;/span&gt;;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (k == 2) opC = &lt;span style="color: #006080"&gt;&amp;quot;/&amp;quot;&lt;/span&gt;;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (k == 3) opC = &lt;span style="color: #006080"&gt;&amp;quot;+&amp;quot;&lt;/span&gt;;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (k == 4) opC = &lt;span style="color: #006080"&gt;&amp;quot;-&amp;quot;&lt;/span&gt;;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;for&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; l
= 1; l &amp;lt;= 4; l++)&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (l == 1) opD = &lt;span style="color: #006080"&gt;&amp;quot;*&amp;quot;&lt;/span&gt;;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (l == 2) opD = &lt;span style="color: #006080"&gt;&amp;quot;/&amp;quot;&lt;/span&gt;;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (l == 3) opD = &lt;span style="color: #006080"&gt;&amp;quot;+&amp;quot;&lt;/span&gt;;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (l == 4) opD = &lt;span style="color: #006080"&gt;&amp;quot;-&amp;quot;&lt;/span&gt;;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; expression = opZ + 1 + opA + 3 + opB +
5 + opC + 7 + opD + 9;&lt;br /&gt;
DataTable dummy = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DataTable();&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;double&lt;/span&gt; result = Convert.ToDouble(dummy.Compute(expression, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.Empty));&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (result == 3)&lt;br /&gt;
Debug.WriteLine(expression + &lt;span style="color: #006080"&gt;&amp;quot; = 3&amp;quot;&lt;/span&gt;);&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (result == 47)&lt;br /&gt;
Debug.WriteLine(expression + &lt;span style="color: #006080"&gt;&amp;quot; = 47&amp;quot;&lt;/span&gt;);&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (result == 18)&lt;br /&gt;
Debug.WriteLine(expression + &lt;span style="color: #006080"&gt;&amp;quot; = 18&amp;quot;&lt;/span&gt;);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
}&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
thanks to &lt;a href="http://stackoverflow.com/questions/174664/operators-as-strings"&gt;http://stackoverflow.com/questions/174664/operators-as-strings&lt;/a&gt; for
the DataTable help.
&lt;/p&gt;
&lt;p&gt;
From &lt;a href="http://stackoverflow.com/questions/4679056/code-smell-in-dynamic-expression"&gt;http://stackoverflow.com/questions/4679056/code-smell-in-dynamic-expression&lt;/a&gt;
&lt;/p&gt;
&lt;h3&gt;TDD
&lt;/h3&gt;
&lt;p&gt;
To help in the refactoring I used tests to make sure I hadn’t broken anything:
&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Text;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Collections.Generic;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Linq;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; Microsoft.VisualStudio.TestTools.UnitTesting;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Data;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Diagnostics;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; Guernsey1&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #008000"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;/// What arithmetical symbols do you have to insert in
between the numbers to get the correct result?&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;/// 1 3 5 7 9 = 3&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;/// 1 3 5 7 9 = 47&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;/// 1 3 5 7 9 = 18&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;/// There may be more than one answer for each one.&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;br /&gt;
[TestClass]&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; UnitTest1&lt;br /&gt;
{&lt;br /&gt;
[TestMethod]&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; GetAnswersForResultIs3()&lt;br /&gt;
{&lt;br /&gt;
List&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt; listOfExpressions = findArithmeticSymbolsInNumericOrder13579ThatGivesThisResult(3);&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; expression &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; listOfExpressions)&lt;br /&gt;
Assert.AreEqual(&lt;span style="color: #006080"&gt;&amp;quot;-1-3+5-7+9&amp;quot;&lt;/span&gt;, expression);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
[TestMethod]&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; GetAnswersForResultIs47()&lt;br /&gt;
{&lt;br /&gt;
List&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt; listOfExpressions = findArithmeticSymbolsInNumericOrder13579ThatGivesThisResult(47);&lt;br /&gt;
Assert.AreEqual(&lt;span style="color: #0000ff"&gt;true&lt;/span&gt;, listOfExpressions.Contains(&lt;span style="color: #006080"&gt;&amp;quot;1*3+5*7+9&amp;quot;&lt;/span&gt;));&lt;br /&gt;
Assert.AreEqual(&lt;span style="color: #0000ff"&gt;true&lt;/span&gt;, listOfExpressions.Contains(&lt;span style="color: #006080"&gt;&amp;quot;-1-3*5+7*9&amp;quot;&lt;/span&gt;));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
[TestMethod]&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; GetAnswersForResultIs18()&lt;br /&gt;
{&lt;br /&gt;
List&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt; listOfExpressions = findArithmeticSymbolsInNumericOrder13579ThatGivesThisResult(18);&lt;br /&gt;
Assert.AreEqual(&lt;span style="color: #0000ff"&gt;true&lt;/span&gt;, listOfExpressions.Contains(&lt;span style="color: #006080"&gt;&amp;quot;-1*3+5+7+9&amp;quot;&lt;/span&gt;));&lt;br /&gt;
Assert.AreEqual(&lt;span style="color: #0000ff"&gt;true&lt;/span&gt;, listOfExpressions.Contains(&lt;span style="color: #006080"&gt;&amp;quot;1+3*5-7+9&amp;quot;&lt;/span&gt;));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; List&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt;
findArithmeticSymbolsInNumericOrder13579ThatGivesThisResult(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; resultExpected) &lt;span style="color: #008000"&gt;//
Jons&lt;/span&gt;
&lt;br /&gt;
{&lt;br /&gt;
List&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt; listOfExpressions = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; List&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt;();&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;[] prefixes = { &lt;span style="color: #006080"&gt;&amp;quot;&amp;quot;&lt;/span&gt;, &lt;span style="color: #006080"&gt;&amp;quot;-&amp;quot;&lt;/span&gt; };&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;[] operators = { &lt;span style="color: #006080"&gt;&amp;quot;*&amp;quot;&lt;/span&gt;, &lt;span style="color: #006080"&gt;&amp;quot;/&amp;quot;&lt;/span&gt;, &lt;span style="color: #006080"&gt;&amp;quot;+&amp;quot;&lt;/span&gt;, &lt;span style="color: #006080"&gt;&amp;quot;-&amp;quot;&lt;/span&gt; };&lt;br /&gt;
IEnumerable&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt; expressions = from prefix &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; prefixes&lt;br /&gt;
from opA &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; operators&lt;br /&gt;
from opB &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; operators&lt;br /&gt;
from opC &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; operators&lt;br /&gt;
from opD &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; operators&lt;br /&gt;
select prefix + 1 + opA + 3 + opB + 5 + opC + 7 + opD + 9;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; expression &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; expressions)&lt;br /&gt;
{&lt;br /&gt;
DataTable dummy = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DataTable();&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;double&lt;/span&gt; result = Convert.ToDouble(dummy.Compute(expression, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.Empty));&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (result == resultExpected)&lt;br /&gt;
listOfExpressions.Add(expression);&lt;br /&gt;
}&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;return&lt;/span&gt; listOfExpressions;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; List&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt;
findArithmeticSymbolsInNumericOrder13579ThatGivesThisResult(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; resultExpected) &lt;span style="color: #008000"&gt;//
Cines&lt;/span&gt;
&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;[] prefixes = { &lt;span style="color: #006080"&gt;&amp;quot;&amp;quot;&lt;/span&gt;, &lt;span style="color: #006080"&gt;&amp;quot;-&amp;quot;&lt;/span&gt; };&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;[] operators = { &lt;span style="color: #006080"&gt;&amp;quot;*&amp;quot;&lt;/span&gt;, &lt;span style="color: #006080"&gt;&amp;quot;/&amp;quot;&lt;/span&gt;, &lt;span style="color: #006080"&gt;&amp;quot;+&amp;quot;&lt;/span&gt;, &lt;span style="color: #006080"&gt;&amp;quot;-&amp;quot;&lt;/span&gt; };&lt;br /&gt;
List&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt; listOfExpressions = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; List&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt;();&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; opA &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; operators)&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; opB &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; operators)&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; opC &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; operators)&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; opD &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; operators)&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; prefix &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; prefixes)&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; expression = prefix + 1 + opA + 3 + opB
+ 5 + opC + 7 + opD + 9;&lt;br /&gt;
DataTable dummy = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DataTable();&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;double&lt;/span&gt; result = Convert.ToDouble(dummy.Compute(expression, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.Empty));&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (result == resultExpected)&lt;br /&gt;
listOfExpressions.Add(expression);&lt;br /&gt;
}&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;return&lt;/span&gt; listOfExpressions;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; List&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt;
findArithmeticSymbolsInNumericOrder13579ThatGivesThisResult(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; resultExpected) &lt;span style="color: #008000"&gt;//
Anton1&lt;/span&gt;
&lt;br /&gt;
{&lt;br /&gt;
List&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt; listOfExpressions = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; List&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt;();&lt;br /&gt;
var calculator = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DataTable();&lt;br /&gt;
var operators = &lt;span style="color: #006080"&gt;&amp;quot;*/+-&amp;quot;&lt;/span&gt;;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;for&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; i
= 0; i &amp;lt; 0x200; ++i)&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; expression = String.Format(&lt;span style="color: #006080"&gt;&amp;quot;{0}1{1}3{2}5{3}7{4}9&amp;quot;&lt;/span&gt;,&lt;br /&gt;
(i &amp;amp; 0x100) != 0 ? &lt;span style="color: #006080"&gt;&amp;quot;-&amp;quot;&lt;/span&gt; : &lt;span style="color: #006080"&gt;&amp;quot;&amp;quot;&lt;/span&gt;,&lt;br /&gt;
operators[(i &amp;gt;&amp;gt; 0) &amp;amp; 3],&lt;br /&gt;
operators[(i &amp;gt;&amp;gt; 2) &amp;amp; 3],&lt;br /&gt;
operators[(i &amp;gt;&amp;gt; 4) &amp;amp; 3],&lt;br /&gt;
operators[(i &amp;gt;&amp;gt; 6) &amp;amp; 3]);&lt;br /&gt;
&lt;br /&gt;
var result = calculator.Compute(expression, String.Empty);&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (Convert.ToDouble(result) == resultExpected)&lt;br /&gt;
listOfExpressions.Add(expression);&lt;br /&gt;
}&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;return&lt;/span&gt; listOfExpressions;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; List&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt;
findArithmeticSymbolsInNumericOrder13579ThatGivesThisResult(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; resultExpected) &lt;span style="color: #008000"&gt;//
Anton2 - not working yet.. how to get the listOfExpressions?&lt;/span&gt;
&lt;br /&gt;
{&lt;br /&gt;
List&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt; listOfExpressions = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; List&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt;();&lt;br /&gt;
var operators = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Func&amp;lt;&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;&amp;gt;[]
{&lt;br /&gt;
(a, b) =&amp;gt; a + b,&lt;br /&gt;
(a, b) =&amp;gt; a - b,&lt;br /&gt;
(a, b) =&amp;gt; a * b,&lt;br /&gt;
(a, b) =&amp;gt; a / b 
&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;for&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; i
= 0; i &amp;lt; 0x200; ++i)&lt;br /&gt;
{&lt;br /&gt;
var stack = 0; &lt;span style="color: #008000"&gt;// max stack depth is 2 because only 2
priorities&lt;/span&gt;
&lt;br /&gt;
var last = 0; &lt;span style="color: #008000"&gt;// imitate + for lowest precedence&lt;/span&gt;
&lt;br /&gt;
var &lt;span style="color: #0000ff"&gt;value&lt;/span&gt; = (i &amp;amp; 0x100) != 0 ? -1 : 1;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;for&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; j
= 0; j &amp;lt; 5; ++j) &lt;span style="color: #008000"&gt;// extra item to force last reduction&lt;/span&gt;
&lt;br /&gt;
{&lt;br /&gt;
var oper = (i &amp;gt;&amp;gt; j * 2) &amp;amp; 3; &lt;span style="color: #008000"&gt;// &amp;quot;input&amp;quot;
operator&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (oper / 2 &amp;lt;= last / 2) &lt;span style="color: #008000"&gt;//
reduce?&lt;/span&gt;
&lt;br /&gt;
{&lt;br /&gt;
stack = operators[last](stack, &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;);&lt;br /&gt;
}&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;else&lt;/span&gt; &lt;span style="color: #008000"&gt;// stack is
empty; prepare to shift&lt;/span&gt;
&lt;br /&gt;
stack = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (j == 4) &lt;span style="color: #0000ff"&gt;break&lt;/span&gt;;&lt;br /&gt;
&lt;br /&gt;
last = oper; &lt;span style="color: #008000"&gt;// shift operator&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;value&lt;/span&gt; = 3 + j * 2; &lt;span style="color: #008000"&gt;//
&amp;quot;input&amp;quot; number&lt;/span&gt;
&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
&lt;span style="color: #008000"&gt;// result in stack&lt;/span&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;return&lt;/span&gt; listOfExpressions;&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
}&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=5972b679-3392-41a7-8fd6-69401bdaaa8b" /&gt;</description>
      <category>c# language</category>
      <category>Competitions</category>
    </item>
    <item>
      <trackback:ping>http://www.programgood.net/Trackback.aspx?guid=8e1d06be-a88b-4ec7-8f08-ce977b34c245</trackback:ping>
      <pingback:server>http://www.programgood.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.programgood.net/PermaLink,guid,8e1d06be-a88b-4ec7-8f08-ce977b34c245.aspx</pingback:target>
      <dc:creator>Dave Mateer</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="http://weblogs.asp.net/scottgu/archive/2007/04/08/new-orcas-language-feature-lambda-expressions.aspx">Lambda
expressions</a> are a simpler syntax for anonymous delegates
</p>
        <div id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <span style="color: #008000">//
anonymous delegate</span>
            <br />
var evens = Enumerable<br />
.Range(1, 100)<br />
.Where(<span style="color: #0000ff">delegate</span>(<span style="color: #0000ff">int</span> x)
{ <span style="color: #0000ff">return</span> (x % 2) == 0; })<br />
.ToList();<br /><br /><span style="color: #008000">// lambda expression</span><br />
var evens = Enumerable<br />
.Range(1, 100)<br />
.Where(x =&gt; (x % 2) == 0)<br />
.ToList();</pre>
          <br />
        </div>
        <p>
I think this is clearer:
</p>
        <div id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <span style="color: #008000">//
anonymous delegate</span>
            <br />
IEnumerable&lt;<span style="color: #0000ff">int</span>&gt; evens = Enumerable<br />
.Range(1, 100)<br />
.Where(<span style="color: #0000ff">delegate</span>(<span style="color: #0000ff">int</span> x)
{ <span style="color: #0000ff">return</span> (x % 2) == 0; })<br />
.ToList(); // forcers immediate query evaluation</pre>
          <br />
        </div>
        <p>
Many thanks to <a href="http://stackoverflow.com/questions/167343/c-lambda-expression-why-should-i-use-this">http://stackoverflow.com/questions/167343/c-lambda-expression-why-should-i-use-this</a></p>
        <img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=8e1d06be-a88b-4ec7-8f08-ce977b34c245" />
      </body>
      <title>Lambda Expressions</title>
      <guid isPermaLink="false">http://www.programgood.net/PermaLink,guid,8e1d06be-a88b-4ec7-8f08-ce977b34c245.aspx</guid>
      <link>http://www.programgood.net/2010/12/11/LambdaExpressions.aspx</link>
      <pubDate>Sat, 11 Dec 2010 07:43:38 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a href="http://weblogs.asp.net/scottgu/archive/2007/04/08/new-orcas-language-feature-lambda-expressions.aspx"&gt;Lambda
expressions&lt;/a&gt; are a simpler syntax for anonymous delegates
&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #008000"&gt;//
anonymous delegate&lt;/span&gt;
&lt;br /&gt;
var evens = Enumerable&lt;br /&gt;
.Range(1, 100)&lt;br /&gt;
.Where(&lt;span style="color: #0000ff"&gt;delegate&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; x)
{ &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; (x % 2) == 0; })&lt;br /&gt;
.ToList();&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;// lambda expression&lt;/span&gt;
&lt;br /&gt;
var evens = Enumerable&lt;br /&gt;
.Range(1, 100)&lt;br /&gt;
.Where(x =&amp;gt; (x % 2) == 0)&lt;br /&gt;
.ToList();&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
I think this is clearer:
&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #008000"&gt;//
anonymous delegate&lt;/span&gt;
&lt;br /&gt;
IEnumerable&amp;lt;&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;&amp;gt; evens = Enumerable&lt;br /&gt;
.Range(1, 100)&lt;br /&gt;
.Where(&lt;span style="color: #0000ff"&gt;delegate&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; x)
{ &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; (x % 2) == 0; })&lt;br /&gt;
.ToList(); // forcers immediate query evaluation&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
Many thanks to &lt;a href="http://stackoverflow.com/questions/167343/c-lambda-expression-why-should-i-use-this"&gt;http://stackoverflow.com/questions/167343/c-lambda-expression-why-should-i-use-this&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=8e1d06be-a88b-4ec7-8f08-ce977b34c245" /&gt;</description>
      <category>c# language</category>
    </item>
    <item>
      <trackback:ping>http://www.programgood.net/Trackback.aspx?guid=86e48c73-b2fa-42bd-b8f1-91a4d14a392f</trackback:ping>
      <pingback:server>http://www.programgood.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.programgood.net/PermaLink,guid,86e48c73-b2fa-42bd-b8f1-91a4d14a392f.aspx</pingback:target>
      <dc:creator>Dave Mateer</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
This is a fun site:
</p>
        <p>
          <a href="http://projecteuler.net">http://projecteuler.net</a>
        </p>
        <p>
The first problem is:
</p>
        <p>
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3,
5, 6 and 9. The sum of these multiples is 23. 
</p>
        <p>
Find the sum of all the multiples of 3 or 5 below 1000.
</p>
        <div id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <span style="color: #0000ff">static</span>
            <span style="color: #0000ff">void</span> Main(<span style="color: #0000ff">string</span>[]
args)<br />
{<br /><span style="color: #0000ff">int</span> overallSum = 0;<br /><span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> i
= 1; i &lt; 1000; i++)<br />
{<br /><span style="color: #0000ff">if</span> ((i % 3 == 0) || (i % 5 == 0))<br />
overallSum += i;<br />
}<br />
Console.WriteLine(<span style="color: #006080">"overall sum is: "</span> +
overallSum.ToString());<br />
Console.ReadLine();<br />
}<br />
// should be 233168</pre>
          <br />
        </div>
        <p>
or Phils way:
</p>
        <div id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <span style="color: #008000">//Find
the sum of all the multiples of 3 or 5 below 1000.</span>
            <br />
            <span style="color: #008000">//There is a summation formula which states</span>
            <br />
            <span style="color: #008000">//The sum of all numbers from i = 1 to i = n is n(n+1)/2</span>
            <br />
            <span style="color: #0000ff">static</span>
            <span style="color: #0000ff">void</span> Main(<span style="color: #0000ff">string</span>[]
args)<br />
{<br /><span style="color: #0000ff">int</span> total = (3 * Convert.ToInt32(999 / 3) * (Convert.ToInt32((999
/ 3)) + 1)) / 2<br />
+ (5 * Convert.ToInt32(999 / 5) * (Convert.ToInt32((999 / 5)) + 1)) / 2<br />
- (15 * Convert.ToInt32(999 / 15) * (Convert.ToInt32((999 / 15)) + 1)) / 2;<br /><br />
Console.WriteLine(<span style="color: #006080">"overall sum is: "</span> +
total.ToString());<br />
Console.ReadLine();<br /><br />
}</pre>
          <br />
        </div>
        <p>
from <a href="http://answers.yahoo.com/question/index?qid=20100422031504AAfmpJ5">http://answers.yahoo.com/question/index?qid=20100422031504AAfmpJ5</a>)
</p>
        <p>
or Simons way using method syntax (or fluent)
</p>
        <div id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <span style="color: #0000ff">int</span> result
= Enumerable.Range(0, 1000) <span style="color: #008000">// generates a sequence of
numbers in a range</span><br />
.Where(i =&gt; i % 3 == 0 || i % 5 == 0) <span style="color: #008000">// filter using
lambda expression </span><br />
.Sum(); // sum of int32 <span style="color: #0000ff">using</span> extension methods</pre>
          <br />
        </div>
        <div id="codeSnippetWrapper">
          <br />
and for fun, using method and query syntax 
</div>
        <div> 
</div>
        <div id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <span style="color: #008000">//
get the ones divisible by 3 in the list - Method syntax</span>
            <br />
IEnumerable&lt;<span style="color: #0000ff">int</span>&gt; listOfDivisibleBy3Method
= listOfInts<br />
.Where(i =&gt; i % 3 == 0);<br /><br /><span style="color: #008000">// get the ones divisible by 3 in the list - Query syntax</span><br />
IEnumerable&lt;<span style="color: #0000ff">int</span>&gt; listOfDivisibleBy3Query
= from number <span style="color: #0000ff">in</span> listOfInts<br /><span style="color: #0000ff">where</span> (number % 3 == 0)<br />
select number;<br /></pre>
          <br />
        </div>
        <p>
          <a href="http://stackoverflow.com/questions/214500/which-linq-syntax-do-you-prefer-fluent-or-query-expression">http://stackoverflow.com/questions/214500/which-linq-syntax-do-you-prefer-fluent-or-query-expression</a>
        </p>
        <img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=86e48c73-b2fa-42bd-b8f1-91a4d14a392f" />
      </body>
      <title>Projecteuler.net – Problem #1 (Linq Method and Query Syntax)</title>
      <guid isPermaLink="false">http://www.programgood.net/PermaLink,guid,86e48c73-b2fa-42bd-b8f1-91a4d14a392f.aspx</guid>
      <link>http://www.programgood.net/2010/12/08/ProjecteulernetProblem1LinqMethodAndQuerySyntax.aspx</link>
      <pubDate>Wed, 08 Dec 2010 04:42:36 GMT</pubDate>
      <description>&lt;p&gt;
This is a fun site:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://projecteuler.net"&gt;http://projecteuler.net&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
The first problem is:
&lt;/p&gt;
&lt;p&gt;
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3,
5, 6 and 9. The sum of these multiples is 23. 
&lt;/p&gt;
&lt;p&gt;
Find the sum of all the multiples of 3 or 5 below 1000.
&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Main(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;[]
args)&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; overallSum = 0;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;for&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; i
= 1; i &amp;lt; 1000; i++)&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; ((i % 3 == 0) || (i % 5 == 0))&lt;br /&gt;
overallSum += i;&lt;br /&gt;
}&lt;br /&gt;
Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;overall sum is: &amp;quot;&lt;/span&gt; +
overallSum.ToString());&lt;br /&gt;
Console.ReadLine();&lt;br /&gt;
}&lt;br /&gt;
// should be 233168&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
or Phils way:
&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #008000"&gt;//Find
the sum of all the multiples of 3 or 5 below 1000.&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;//There is a summation formula which states&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;//The sum of all numbers from i = 1 to i = n is n(n+1)/2&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Main(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;[]
args)&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; total = (3 * Convert.ToInt32(999 / 3) * (Convert.ToInt32((999
/ 3)) + 1)) / 2&lt;br /&gt;
+ (5 * Convert.ToInt32(999 / 5) * (Convert.ToInt32((999 / 5)) + 1)) / 2&lt;br /&gt;
- (15 * Convert.ToInt32(999 / 15) * (Convert.ToInt32((999 / 15)) + 1)) / 2;&lt;br /&gt;
&lt;br /&gt;
Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;overall sum is: &amp;quot;&lt;/span&gt; +
total.ToString());&lt;br /&gt;
Console.ReadLine();&lt;br /&gt;
&lt;br /&gt;
}&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
from &lt;a href="http://answers.yahoo.com/question/index?qid=20100422031504AAfmpJ5"&gt;http://answers.yahoo.com/question/index?qid=20100422031504AAfmpJ5&lt;/a&gt;)
&lt;/p&gt;
&lt;p&gt;
or Simons way using method syntax (or fluent)
&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; result
= Enumerable.Range(0, 1000) &lt;span style="color: #008000"&gt;// generates a sequence of
numbers in a range&lt;/span&gt;
&lt;br /&gt;
.Where(i =&amp;gt; i % 3 == 0 || i % 5 == 0) &lt;span style="color: #008000"&gt;// filter using
lambda expression &lt;/span&gt;
&lt;br /&gt;
.Sum(); // sum of int32 &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; extension methods&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;br /&gt;
and for fun, using method and query syntax 
&lt;/div&gt;
&lt;div&gt;&amp;#160;
&lt;/div&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #008000"&gt;//
get the ones divisible by 3 in the list - Method syntax&lt;/span&gt;
&lt;br /&gt;
IEnumerable&amp;lt;&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;&amp;gt; listOfDivisibleBy3Method
= listOfInts&lt;br /&gt;
.Where(i =&amp;gt; i % 3 == 0);&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;// get the ones divisible by 3 in the list - Query syntax&lt;/span&gt;
&lt;br /&gt;
IEnumerable&amp;lt;&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;&amp;gt; listOfDivisibleBy3Query
= from number &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; listOfInts&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;where&lt;/span&gt; (number % 3 == 0)&lt;br /&gt;
select number;&lt;br /&gt;
&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;a href="http://stackoverflow.com/questions/214500/which-linq-syntax-do-you-prefer-fluent-or-query-expression"&gt;http://stackoverflow.com/questions/214500/which-linq-syntax-do-you-prefer-fluent-or-query-expression&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=86e48c73-b2fa-42bd-b8f1-91a4d14a392f" /&gt;</description>
      <category>c# language</category>
      <category>Euler</category>
      <category>Linq</category>
    </item>
    <item>
      <trackback:ping>http://www.programgood.net/Trackback.aspx?guid=0b81882d-55ab-4c12-aa81-b7571af20a39</trackback:ping>
      <pingback:server>http://www.programgood.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.programgood.net/PermaLink,guid,0b81882d-55ab-4c12-aa81-b7571af20a39.aspx</pingback:target>
      <dc:creator>Dave Mateer</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
something like:
</p>
        <p>
Array arraything = "abc, def"; 
</p>
        <p>
           foreach (var item in
arrayThing) 
<br />
           { 
<br />
              
Console.WriteLine("item is: " + item); 
<br />
           }
</p>
        <p>
 
</p>
        <p>
This works becuase an array in enumerable
</p>
        <img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=0b81882d-55ab-4c12-aa81-b7571af20a39" />
      </body>
      <title>Iterating over an Array</title>
      <guid isPermaLink="false">http://www.programgood.net/PermaLink,guid,0b81882d-55ab-4c12-aa81-b7571af20a39.aspx</guid>
      <link>http://www.programgood.net/2010/11/18/IteratingOverAnArray.aspx</link>
      <pubDate>Thu, 18 Nov 2010 00:56:35 GMT</pubDate>
      <description>&lt;p&gt;
something like:
&lt;/p&gt;
&lt;p&gt;
Array arraything = &amp;quot;abc, def&amp;quot;; 
&lt;/p&gt;
&lt;p&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; foreach (var item in
arrayThing) 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; { 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
Console.WriteLine(&amp;quot;item is: &amp;quot; + item); 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
This works becuase an array in enumerable
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=0b81882d-55ab-4c12-aa81-b7571af20a39" /&gt;</description>
      <category>c# language</category>
    </item>
    <item>
      <trackback:ping>http://www.programgood.net/Trackback.aspx?guid=e8a1774c-97d5-4597-aec9-0c3e95162dbb</trackback:ping>
      <pingback:server>http://www.programgood.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.programgood.net/PermaLink,guid,e8a1774c-97d5-4597-aec9-0c3e95162dbb.aspx</pingback:target>
      <dc:creator>Dave Mateer</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <div id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">DateTime EffectiveDate;<br /><span style="color: #0000ff">if</span> (!DateTime.TryParse(cert.GetEffectiveDateString(), <span style="color: #0000ff">out</span> EffectiveDate))<br />
{<br /><span style="color: #0000ff">return</span><span style="color: #0000ff">false</span>;<br />
}</pre>
          <br />
        </div>
        <img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=e8a1774c-97d5-4597-aec9-0c3e95162dbb" />
      </body>
      <title>Out Parameter</title>
      <guid isPermaLink="false">http://www.programgood.net/PermaLink,guid,e8a1774c-97d5-4597-aec9-0c3e95162dbb.aspx</guid>
      <link>http://www.programgood.net/2010/11/17/OutParameter.aspx</link>
      <pubDate>Wed, 17 Nov 2010 21:36:01 GMT</pubDate>
      <description>&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;DateTime EffectiveDate;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!DateTime.TryParse(cert.GetEffectiveDateString(), &lt;span style="color: #0000ff"&gt;out&lt;/span&gt; EffectiveDate))&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;;&lt;br /&gt;
}&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=e8a1774c-97d5-4597-aec9-0c3e95162dbb" /&gt;</description>
      <category>c# language</category>
    </item>
    <item>
      <trackback:ping>http://www.programgood.net/Trackback.aspx?guid=15bb2001-4bd9-4707-bcab-e9e81dc584fe</trackback:ping>
      <pingback:server>http://www.programgood.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.programgood.net/PermaLink,guid,15bb2001-4bd9-4707-bcab-e9e81dc584fe.aspx</pingback:target>
      <dc:creator>Dave Mateer</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I saw some interesting code:
</p>
        <div id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <span style="color: #0000ff">for</span> (;
contours != <span style="color: #0000ff">null</span>; contours = contours.HNext)<br />
{<br />
Contour&lt;Point&gt; approxContour = contours.ApproxPoly(contours.Perimeter * 0.02,
contours.Storage);<br />
img.Draw(approxContour, <span style="color: #0000ff">new</span> Bgr(1, 1, 251), 2);<br />
}</pre>
          <br />
        </div>
        <p>
        </p>
        <p>
I’d never seen the initial part of the for statement missing so I played:
</p>
        <div id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <span style="color: #0000ff">class</span> Program<br />
{<br /><span style="color: #0000ff">static</span><span style="color: #0000ff">void</span> Main(<span style="color: #0000ff">string</span>[]
args)<br />
{<br /><span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> i
= 1; i &lt;= 5; i++) <span style="color: #008000">// normal usage</span><br />
{<br />
Console.WriteLine(<span style="color: #006080">"i count is {0}"</span>,
i);<br />
}<br /><br /><span style="color: #0000ff">int</span> k = 1;<br /><span style="color: #0000ff">for</span> (; k&lt;=5; k++) <span style="color: #008000">//
missing first bit</span><br />
{<br />
Console.WriteLine(<span style="color: #006080">"k count is {0}"</span>,
k);<br />
}<br /><br /><span style="color: #0000ff">int</span> m = 1;<br /><span style="color: #0000ff">for</span> (; m &lt;= 5;) <span style="color: #008000">//
missing last bit too</span><br />
{<br />
Console.WriteLine(<span style="color: #006080">"m count is {0}"</span>,
m);<br />
m++;<br />
}<br /><br /><span style="color: #0000ff">for</span> (; ; ) <span style="color: #008000">// infinite
loop, never breaks out</span><br />
{<br /><br />
}<br /><br /><br /><br />
Contour contA = <span style="color: #0000ff">new</span> Contour { x = 10, y = 20 };<br />
Contour contB = <span style="color: #0000ff">new</span> Contour { x = 50, y = 60 };<br />
Contour contC = <span style="color: #0000ff">new</span> Contour { x = 90, y = 100
};<br /><br />
List&lt;Contour&gt; listOfContours = <span style="color: #0000ff">new</span> List&lt;Contour&gt;();<br />
listOfContours.Add(contA); <span style="color: #008000">// better way to add to a
collection?</span><br />
listOfContours.Add(contB);<br />
listOfContours.Add(contC);<br /><br /><span style="color: #0000ff">foreach</span> (Contour contour <span style="color: #0000ff">in</span> listOfContours)<br />
{<br />
Console.WriteLine(<span style="color: #006080">"x is {0}"</span>, contour.x.ToString());<br />
Console.WriteLine(<span style="color: #006080">"y is {0}"</span>, contour.y.ToString());<br />
Console.WriteLine();<br />
}<br /><br /><span style="color: #0000ff">int</span> j = 0;<br /><span style="color: #0000ff">while</span> (j &lt; 5)<br />
{<br />
Console.WriteLine(<span style="color: #006080">"While loop counter is {0}"</span>,
j.ToString());<br />
j++;<br />
}<br />
}<br />
}<br /><br /><span style="color: #0000ff">class</span> Contour<br />
{<br /><span style="color: #0000ff">public</span><span style="color: #0000ff">int</span> x;<br /><span style="color: #0000ff">public</span><span style="color: #0000ff">int</span> y;<br /><span style="color: #008000">//public int x { get; set; }</span><br /><span style="color: #008000">//public int y { get; set; }</span><br />
}</pre>
          <br />
        </div>
        <div id="codeSnippetWrapper">
          <br />
        </div>
        <img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=15bb2001-4bd9-4707-bcab-e9e81dc584fe" />
      </body>
      <title>For Loops</title>
      <guid isPermaLink="false">http://www.programgood.net/PermaLink,guid,15bb2001-4bd9-4707-bcab-e9e81dc584fe.aspx</guid>
      <link>http://www.programgood.net/2010/09/25/ForLoops.aspx</link>
      <pubDate>Sat, 25 Sep 2010 02:21:54 GMT</pubDate>
      <description>&lt;p&gt;
I saw some interesting code:
&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;for&lt;/span&gt; (;
contours != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;; contours = contours.HNext)&lt;br /&gt;
{&lt;br /&gt;
Contour&amp;lt;Point&amp;gt; approxContour = contours.ApproxPoly(contours.Perimeter * 0.02,
contours.Storage);&lt;br /&gt;
img.Draw(approxContour, &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Bgr(1, 1, 251), 2);&lt;br /&gt;
}&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
I’d never seen the initial part of the for statement missing so I played:
&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Program&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Main(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;[]
args)&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;for&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; i
= 1; i &amp;lt;= 5; i++) &lt;span style="color: #008000"&gt;// normal usage&lt;/span&gt;
&lt;br /&gt;
{&lt;br /&gt;
Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;i count is {0}&amp;quot;&lt;/span&gt;,
i);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; k = 1;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;for&lt;/span&gt; (; k&amp;lt;=5; k++) &lt;span style="color: #008000"&gt;//
missing first bit&lt;/span&gt;
&lt;br /&gt;
{&lt;br /&gt;
Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;k count is {0}&amp;quot;&lt;/span&gt;,
k);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; m = 1;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;for&lt;/span&gt; (; m &amp;lt;= 5;) &lt;span style="color: #008000"&gt;//
missing last bit too&lt;/span&gt;
&lt;br /&gt;
{&lt;br /&gt;
Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;m count is {0}&amp;quot;&lt;/span&gt;,
m);&lt;br /&gt;
m++;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;for&lt;/span&gt; (; ; ) &lt;span style="color: #008000"&gt;// infinite
loop, never breaks out&lt;/span&gt;
&lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Contour contA = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Contour { x = 10, y = 20 };&lt;br /&gt;
Contour contB = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Contour { x = 50, y = 60 };&lt;br /&gt;
Contour contC = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Contour { x = 90, y = 100
};&lt;br /&gt;
&lt;br /&gt;
List&amp;lt;Contour&amp;gt; listOfContours = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; List&amp;lt;Contour&amp;gt;();&lt;br /&gt;
listOfContours.Add(contA); &lt;span style="color: #008000"&gt;// better way to add to a
collection?&lt;/span&gt;
&lt;br /&gt;
listOfContours.Add(contB);&lt;br /&gt;
listOfContours.Add(contC);&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (Contour contour &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; listOfContours)&lt;br /&gt;
{&lt;br /&gt;
Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;x is {0}&amp;quot;&lt;/span&gt;, contour.x.ToString());&lt;br /&gt;
Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;y is {0}&amp;quot;&lt;/span&gt;, contour.y.ToString());&lt;br /&gt;
Console.WriteLine();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; j = 0;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;while&lt;/span&gt; (j &amp;lt; 5)&lt;br /&gt;
{&lt;br /&gt;
Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;While loop counter is {0}&amp;quot;&lt;/span&gt;,
j.ToString());&lt;br /&gt;
j++;&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Contour&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; x;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; y;&lt;br /&gt;
&lt;span style="color: #008000"&gt;//public int x { get; set; }&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;//public int y { get; set; }&lt;/span&gt;
&lt;br /&gt;
}&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=15bb2001-4bd9-4707-bcab-e9e81dc584fe" /&gt;</description>
      <category>c# language</category>
    </item>
    <item>
      <trackback:ping>http://www.programgood.net/Trackback.aspx?guid=751b2afa-02ce-4603-b349-1052756bbf6d</trackback:ping>
      <pingback:server>http://www.programgood.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.programgood.net/PermaLink,guid,751b2afa-02ce-4603-b349-1052756bbf6d.aspx</pingback:target>
      <dc:creator>Dave Mateer</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I’m getting data using LINQ to SQL, then showing on the front end.  If I want
a null coming from the database to default to something:
</p>
        <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">&lt;telerik:GridTemplateColumn HeaderText=<span style="color: #006080">"Image"</span> UniqueName=<span style="color: #006080">"Image"</span>&gt; 
<br />
&lt;ItemTemplate&gt; 
<br />
&lt;asp:Label ID=<span style="color: #006080">"asdf"</span> runat=<span style="color: #006080">"server"</span> Text=<span style="color: #006080">'&lt;%#
String.IsNullOrEmpty(Convert.ToString(Eval("Image1"))) ? "noImage.jpg"
: Eval("Image1")%&gt;'</span>&gt;&lt;/asp:Label&gt;<br />
&lt;a href=<span style="color: #006080">"&lt;%=VirtualPathUtility.ToAbsolute("</span>~/<span style="color: #006080">")%&gt;showFrontEndMaterialDetail.aspx?materialId=&lt;%#
Eval("</span>Id<span style="color: #006080">")%&gt;"</span>&gt;<br />
&lt;img src=<span style="color: #006080">"&lt;%=VirtualPathUtility.ToAbsolute("</span>~/<span style="color: #006080">")%&gt;Images/Uploaded/Thumbs/&lt;%#
Eval("</span>Image1<span style="color: #006080">") ?? "</span>noPhoto.jpg<span style="color: #006080">"
%&gt;"</span>&gt;&lt;/img&gt;&lt;/a&gt;<br /><br />
&lt;/ItemTemplate&gt; 
<br />
&lt;/telerik:GridTemplateColumn&gt;</pre>
          <br />
        </div>
        <div>
          <br />
Thanks to these people:
</div>
        <div>
          <a href="http://stackoverflow.com/questions/3411155/c-eval-aspx-fun">http://stackoverflow.com/questions/3411155/c-eval-aspx-fun</a> 
</div>
        <div> 
</div>
        <p>
        </p>
        <p>
        </p>
        <p>
          <a href="http://stackoverflow.com/questions/3410942/linq-to-sql-default-value-nullable">http://stackoverflow.com/questions/3410942/linq-to-sql-default-value-nullable</a>
        </p>
        <img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=751b2afa-02ce-4603-b349-1052756bbf6d" />
      </body>
      <title>Default Values in Eval</title>
      <guid isPermaLink="false">http://www.programgood.net/PermaLink,guid,751b2afa-02ce-4603-b349-1052756bbf6d.aspx</guid>
      <link>http://www.programgood.net/2010/08/05/DefaultValuesInEval.aspx</link>
      <pubDate>Thu, 05 Aug 2010 02:25:49 GMT</pubDate>
      <description>&lt;p&gt;
I’m getting data using LINQ to SQL, then showing on the front end.&amp;#160; If I want
a null coming from the database to default to something:
&lt;/p&gt;
&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&amp;lt;telerik:GridTemplateColumn HeaderText=&lt;span style="color: #006080"&gt;&amp;quot;Image&amp;quot;&lt;/span&gt; UniqueName=&lt;span style="color: #006080"&gt;&amp;quot;Image&amp;quot;&lt;/span&gt;&amp;gt; 
&lt;br /&gt;
&amp;lt;ItemTemplate&amp;gt; 
&lt;br /&gt;
&amp;lt;asp:Label ID=&lt;span style="color: #006080"&gt;&amp;quot;asdf&amp;quot;&lt;/span&gt; runat=&lt;span style="color: #006080"&gt;&amp;quot;server&amp;quot;&lt;/span&gt; Text=&lt;span style="color: #006080"&gt;'&amp;lt;%#
String.IsNullOrEmpty(Convert.ToString(Eval(&amp;quot;Image1&amp;quot;))) ? &amp;quot;noImage.jpg&amp;quot;
: Eval(&amp;quot;Image1&amp;quot;)%&amp;gt;'&lt;/span&gt;&amp;gt;&amp;lt;/asp:Label&amp;gt;&lt;br /&gt;
&amp;lt;a href=&lt;span style="color: #006080"&gt;&amp;quot;&amp;lt;%=VirtualPathUtility.ToAbsolute(&amp;quot;&lt;/span&gt;~/&lt;span style="color: #006080"&gt;&amp;quot;)%&amp;gt;showFrontEndMaterialDetail.aspx?materialId=&amp;lt;%#
Eval(&amp;quot;&lt;/span&gt;Id&lt;span style="color: #006080"&gt;&amp;quot;)%&amp;gt;&amp;quot;&lt;/span&gt;&amp;gt;&lt;br /&gt;
&amp;lt;img src=&lt;span style="color: #006080"&gt;&amp;quot;&amp;lt;%=VirtualPathUtility.ToAbsolute(&amp;quot;&lt;/span&gt;~/&lt;span style="color: #006080"&gt;&amp;quot;)%&amp;gt;Images/Uploaded/Thumbs/&amp;lt;%#
Eval(&amp;quot;&lt;/span&gt;Image1&lt;span style="color: #006080"&gt;&amp;quot;) ?? &amp;quot;&lt;/span&gt;noPhoto.jpg&lt;span style="color: #006080"&gt;&amp;quot;
%&amp;gt;&amp;quot;&lt;/span&gt;&amp;gt;&amp;lt;/img&amp;gt;&amp;lt;/a&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/ItemTemplate&amp;gt; 
&lt;br /&gt;
&amp;lt;/telerik:GridTemplateColumn&amp;gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
Thanks to these people:
&lt;/div&gt;
&lt;div&gt;&lt;a href="http://stackoverflow.com/questions/3411155/c-eval-aspx-fun"&gt;http://stackoverflow.com/questions/3411155/c-eval-aspx-fun&lt;/a&gt;&amp;#160;
&lt;/div&gt;
&lt;div&gt;&amp;#160;
&lt;/div&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://stackoverflow.com/questions/3410942/linq-to-sql-default-value-nullable"&gt;http://stackoverflow.com/questions/3410942/linq-to-sql-default-value-nullable&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=751b2afa-02ce-4603-b349-1052756bbf6d" /&gt;</description>
      <category>c# language</category>
    </item>
    <item>
      <trackback:ping>http://www.programgood.net/Trackback.aspx?guid=cf5cab24-c664-4dea-8f81-eae35517bcbb</trackback:ping>
      <pingback:server>http://www.programgood.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.programgood.net/PermaLink,guid,cf5cab24-c664-4dea-8f81-eae35517bcbb.aspx</pingback:target>
      <dc:creator>Dave Mateer</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
When displaying a repeater on an aspx page:
</p>
        <div id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">&lt;asp:Repeater ID=<span style="color: #006080">"Repeater1"</span> runat=<span style="color: #006080">"server"</span>&gt;<br />
&lt;ItemTemplate&gt;<br />
&lt;%#DataBinder.Eval(Container.DataItem, <span style="color: #006080">"FileName"</span>)%&gt;<br />
&lt;/ItemTemplate&gt;<br />
&lt;/asp:Repeater&gt;</pre>
          <br />
        </div>
        <p>
or shorter:
</p>
        <div id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">&lt;asp:Repeater ID=<span style="color: #006080">"Repeater1"</span> runat=<span style="color: #006080">"server"</span>&gt;<br />
&lt;ItemTemplate&gt;<br />
&lt;%#Eval(<span style="color: #006080">"FileName"</span>)%&gt;<br />
&lt;/ItemTemplate&gt;<br />
&lt;/asp:Repeater&gt;</pre>
          <br />
        </div>
        <p>
        </p>
        <p>
It is important to remember to make FileName a property and not just a public field
ie this works
</p>
        <div id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <span style="color: #0000ff">public</span>
            <span style="color: #0000ff">class</span> ImageThing<br />
{<br /><span style="color: #0000ff">public</span><span style="color: #0000ff">string</span> FileName
{get; set; }<br />
}<br /><br /><span style="color: #0000ff">private</span><span style="color: #0000ff">void</span> DisplayThumbnailImages()<br />
{<br />
ImageThing imageThing1 = <span style="color: #0000ff">new</span> ImageThing();<br />
ImageThing imageThing2 = <span style="color: #0000ff">new</span> ImageThing();<br />
imageThing1.FileName = <span style="color: #006080">"asdf.jpg"</span>;<br />
imageThing2.FileName = <span style="color: #006080">"aaa.jpg"</span>;<br /><br />
List&lt;ImageThing&gt; imagesToRender = <span style="color: #0000ff">new</span> List&lt;ImageThing&gt;();<br />
imagesToRender.Add(imageThing1);<br />
imagesToRender.Add(imageThing2);<br /><br />
Repeater1.DataSource = imagesToRender;<br />
Repeater1.DataBind();<br />
}</pre>
          <br />
        </div>
        <p>
this doesn’t
</p>
        <div id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <span style="color: #0000ff">public</span>
            <span style="color: #0000ff">class</span> ImageThing<br />
{<br /><span style="color: #0000ff">public</span><span style="color: #0000ff">string</span> FileName;<br />
}</pre>
          <br />
        </div>
        <p>
A property encapsulates a field.
</p>
        <img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=cf5cab24-c664-4dea-8f81-eae35517bcbb" />
      </body>
      <title>Difference Between a Property and a Field using Repeaters</title>
      <guid isPermaLink="false">http://www.programgood.net/PermaLink,guid,cf5cab24-c664-4dea-8f81-eae35517bcbb.aspx</guid>
      <link>http://www.programgood.net/2010/08/04/DifferenceBetweenAPropertyAndAFieldUsingRepeaters.aspx</link>
      <pubDate>Wed, 04 Aug 2010 23:04:00 GMT</pubDate>
      <description>&lt;p&gt;
When displaying a repeater on an aspx page:
&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&amp;lt;asp:Repeater ID=&lt;span style="color: #006080"&gt;&amp;quot;Repeater1&amp;quot;&lt;/span&gt; runat=&lt;span style="color: #006080"&gt;&amp;quot;server&amp;quot;&lt;/span&gt;&amp;gt;&lt;br /&gt;
&amp;lt;ItemTemplate&amp;gt;&lt;br /&gt;
&amp;lt;%#DataBinder.Eval(Container.DataItem, &lt;span style="color: #006080"&gt;&amp;quot;FileName&amp;quot;&lt;/span&gt;)%&amp;gt;&lt;br /&gt;
&amp;lt;/ItemTemplate&amp;gt;&lt;br /&gt;
&amp;lt;/asp:Repeater&amp;gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
or shorter:
&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&amp;lt;asp:Repeater ID=&lt;span style="color: #006080"&gt;&amp;quot;Repeater1&amp;quot;&lt;/span&gt; runat=&lt;span style="color: #006080"&gt;&amp;quot;server&amp;quot;&lt;/span&gt;&amp;gt;&lt;br /&gt;
&amp;lt;ItemTemplate&amp;gt;&lt;br /&gt;
&amp;lt;%#Eval(&lt;span style="color: #006080"&gt;&amp;quot;FileName&amp;quot;&lt;/span&gt;)%&amp;gt;&lt;br /&gt;
&amp;lt;/ItemTemplate&amp;gt;&lt;br /&gt;
&amp;lt;/asp:Repeater&amp;gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
It is important to remember to make FileName a property and not just a public field
ie this works
&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; ImageThing&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; FileName
{get; set; }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; DisplayThumbnailImages()&lt;br /&gt;
{&lt;br /&gt;
ImageThing imageThing1 = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ImageThing();&lt;br /&gt;
ImageThing imageThing2 = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ImageThing();&lt;br /&gt;
imageThing1.FileName = &lt;span style="color: #006080"&gt;&amp;quot;asdf.jpg&amp;quot;&lt;/span&gt;;&lt;br /&gt;
imageThing2.FileName = &lt;span style="color: #006080"&gt;&amp;quot;aaa.jpg&amp;quot;&lt;/span&gt;;&lt;br /&gt;
&lt;br /&gt;
List&amp;lt;ImageThing&amp;gt; imagesToRender = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; List&amp;lt;ImageThing&amp;gt;();&lt;br /&gt;
imagesToRender.Add(imageThing1);&lt;br /&gt;
imagesToRender.Add(imageThing2);&lt;br /&gt;
&lt;br /&gt;
Repeater1.DataSource = imagesToRender;&lt;br /&gt;
Repeater1.DataBind();&lt;br /&gt;
}&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
this doesn’t
&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; ImageThing&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; FileName;&lt;br /&gt;
}&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
A property encapsulates a field.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=cf5cab24-c664-4dea-8f81-eae35517bcbb" /&gt;</description>
      <category>c# language</category>
      <category>SiteFinity</category>
    </item>
    <item>
      <trackback:ping>http://www.programgood.net/Trackback.aspx?guid=6f2f5f74-7c90-4459-8633-4d516ada4778</trackback:ping>
      <pingback:server>http://www.programgood.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.programgood.net/PermaLink,guid,6f2f5f74-7c90-4459-8633-4d516ada4778.aspx</pingback:target>
      <dc:creator>Dave Mateer</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
While trying to figure out what is meant by the 3rd new section in a view in MVC
</p>
        <p>
&lt;%: Html.ActionLink("Edit", "Edit", new { id=item.DinnerID
}) %&gt;
</p>
        <p>
So it is really creating an object with a single property id, which is an int, equal
to that of the item, which is a Dinner.
</p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/AnonymousTypes_D000/image_2.png">
            <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.programgood.net/content/binary/WindowsLiveWriter/AnonymousTypes_D000/image_thumb.png" width="644" height="219" />
          </a>
        </p>
        <p>
“Anonymous types provide a convenient way to encapsulate a set of read-only properties
into a single object without having to first explicitly define a type”
</p>
        <div id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <span style="color: #0000ff">class</span> Program<br />
{<br /><span style="color: #0000ff">static</span><span style="color: #0000ff">void</span> Main(<span style="color: #0000ff">string</span>[]
args)<br />
{<br /><span style="color: #008000">// Anonymous types provide a convenient way to encapsulate
a set of read-only properties</span><br /><span style="color: #008000">// into a single object without having to first explicitly
define a type</span><br />
var person = <span style="color: #0000ff">new</span> { Name = <span style="color: #006080">"Terry"</span>,
Age = 21 };<br />
Console.WriteLine(<span style="color: #006080">"name is "</span> + person.Name);<br />
Console.WriteLine(<span style="color: #006080">"age is "</span> + person.Age.ToString());<br /><br /><span style="color: #008000">// Anonymous types just get rid of Person1 really.</span><br />
Person1 person1 = <span style="color: #0000ff">new</span> Person1 { Name = <span style="color: #006080">"Bill"</span>,
Age = 55 };<br />
Console.WriteLine(<span style="color: #006080">"name is "</span> + person1.Name);<br />
Console.WriteLine(<span style="color: #006080">"age is "</span> + person1.Age.ToString());<br />
}<br />
}<br /><br /><span style="color: #0000ff">class</span> Person1<br />
{<br /><span style="color: #0000ff">public</span><span style="color: #0000ff">string</span> Name
{ get; set; }<br /><span style="color: #0000ff">public</span><span style="color: #0000ff">int</span> Age
{ get; set; }<br />
}</pre>
          <br />
        </div>
        <div id="codeSnippetWrapper">Many thanks to the question here for clarifying:
</div>
        <div> 
</div>
        <div id="codeSnippetWrapper">
          <a title="http://stackoverflow.com/questions/3098643/anonymous-type-syntax-in-asp-net-mvc" href="http://stackoverflow.com/questions/3098643/anonymous-type-syntax-in-asp-net-mvc">http://stackoverflow.com/questions/3098643/anonymous-type-syntax-in-asp-net-mvc</a>
          <br />
        </div>
        <img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=6f2f5f74-7c90-4459-8633-4d516ada4778" />
      </body>
      <title>Anonymous Types</title>
      <guid isPermaLink="false">http://www.programgood.net/PermaLink,guid,6f2f5f74-7c90-4459-8633-4d516ada4778.aspx</guid>
      <link>http://www.programgood.net/2010/06/23/AnonymousTypes.aspx</link>
      <pubDate>Wed, 23 Jun 2010 03:35:49 GMT</pubDate>
      <description>&lt;p&gt;
While trying to figure out what is meant by the 3rd new section in a view in MVC
&lt;/p&gt;
&lt;p&gt;
&amp;lt;%: Html.ActionLink(&amp;quot;Edit&amp;quot;, &amp;quot;Edit&amp;quot;, new { id=item.DinnerID
}) %&amp;gt;
&lt;/p&gt;
&lt;p&gt;
So it is really creating an object with a single property id, which is an int, equal
to that of the item, which is a Dinner.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/AnonymousTypes_D000/image_2.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.programgood.net/content/binary/WindowsLiveWriter/AnonymousTypes_D000/image_thumb.png" width="644" height="219" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
“Anonymous types provide a convenient way to encapsulate a set of read-only properties
into a single object without having to first explicitly define a type”
&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Program&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Main(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;[]
args)&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #008000"&gt;// Anonymous types provide a convenient way to encapsulate
a set of read-only properties&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;// into a single object without having to first explicitly
define a type&lt;/span&gt;
&lt;br /&gt;
var person = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; { Name = &lt;span style="color: #006080"&gt;&amp;quot;Terry&amp;quot;&lt;/span&gt;,
Age = 21 };&lt;br /&gt;
Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;name is &amp;quot;&lt;/span&gt; + person.Name);&lt;br /&gt;
Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;age is &amp;quot;&lt;/span&gt; + person.Age.ToString());&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;// Anonymous types just get rid of Person1 really.&lt;/span&gt;
&lt;br /&gt;
Person1 person1 = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Person1 { Name = &lt;span style="color: #006080"&gt;&amp;quot;Bill&amp;quot;&lt;/span&gt;,
Age = 55 };&lt;br /&gt;
Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;name is &amp;quot;&lt;/span&gt; + person1.Name);&lt;br /&gt;
Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;age is &amp;quot;&lt;/span&gt; + person1.Age.ToString());&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Person1&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; Name
{ get; set; }&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; Age
{ get; set; }&lt;br /&gt;
}&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;div id="codeSnippetWrapper"&gt;Many thanks to the question here for clarifying:
&lt;/div&gt;
&lt;div&gt;&amp;#160;
&lt;/div&gt;
&lt;div id="codeSnippetWrapper"&gt;&lt;a title="http://stackoverflow.com/questions/3098643/anonymous-type-syntax-in-asp-net-mvc" href="http://stackoverflow.com/questions/3098643/anonymous-type-syntax-in-asp-net-mvc"&gt;http://stackoverflow.com/questions/3098643/anonymous-type-syntax-in-asp-net-mvc&lt;/a&gt; 
&lt;br /&gt;
&lt;/div&gt;
&lt;img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=6f2f5f74-7c90-4459-8633-4d516ada4778" /&gt;</description>
      <category>ASP.NET MVC</category>
      <category>c# language</category>
    </item>
    <item>
      <trackback:ping>http://www.programgood.net/Trackback.aspx?guid=f60ce9ab-2c3f-4afe-b2b7-d4ac6d2199c8</trackback:ping>
      <pingback:server>http://www.programgood.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.programgood.net/PermaLink,guid,f60ce9ab-2c3f-4afe-b2b7-d4ac6d2199c8.aspx</pingback:target>
      <dc:creator>Dave Mateer</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Static classes are usually used as ‘utility’ classes
</p>
        <p>
You don’t need an instance
</p>
        <p>
 
</p>
        <div id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <span style="color: #0000ff">class</span> Program<br />
{<br /><span style="color: #0000ff">static</span><span style="color: #0000ff">void</span> Main()<br />
{<br /><span style="color: #0000ff">double</span> result = thing.daveSubtract(10);<br />
Console.WriteLine(result);<br />
}<br />
}<br /><br /><span style="color: #0000ff">static</span><span style="color: #0000ff">class</span> thing<br />
{<br /><span style="color: #0000ff">static</span><span style="color: #0000ff">public</span><span style="color: #0000ff">double</span> daveSubtract(<span style="color: #0000ff">double</span> number)<br />
{<br /><span style="color: #0000ff">return</span> (number - 2);<br />
}<br />
}</pre>
        </div>
        <h3>Extension Methods
</h3>
        <p>
From: http://msdn.microsoft.com/en-us/library/bb383977.aspx
</p>
        <p>
Extension methods enable you to "add" methods to existing types without
creating a new derived type,
</p>
        <p>
Extension methods are a special kind of static method, but they are called as if they
were instance methods on the extended type. 
</p>
        <p>
For client code, there is no apparent difference between calling an extension method
and the methods that are actually defined in a type.
</p>
        <p>
 
</p>
        <div id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <span style="color: #0000ff">using</span> System;<br /><br /><span style="color: #0000ff">namespace</span> ConsoleApplication1<br />
{<br /><span style="color: #0000ff">class</span> Program<br />
{<br /><span style="color: #0000ff">static</span><span style="color: #0000ff">void</span> Main(<span style="color: #0000ff">string</span>[]
args)<br />
{<br /><span style="color: #0000ff">string</span> s = <span style="color: #006080">"hello
extension methods are good"</span>;<br />
Console.WriteLine(s);<br /><span style="color: #0000ff">int</span> i = s.WordCount();<br />
Console.WriteLine(<span style="color: #006080">"number of words is {0}"</span>,
i.ToString());<br />
}<br />
}<br /><br /><span style="color: #0000ff">public</span><span style="color: #0000ff">static</span><span style="color: #0000ff">class</span> MyExtensions<br />
{<br /><span style="color: #0000ff">public</span><span style="color: #0000ff">static</span><span style="color: #0000ff">int</span> WordCount(<span style="color: #0000ff">this</span> String
str)<br />
{<br /><span style="color: #0000ff">return</span> str.Split(<span style="color: #0000ff">new</span><span style="color: #0000ff">char</span>[]
{ <span style="color: #006080">' '</span>, <span style="color: #006080">'.'</span>, <span style="color: #006080">'?'</span> },
StringSplitOptions.RemoveEmptyEntries).Length;<br />
}<br />
}<br />
}</pre>
          <br />
        </div>
        <img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=f60ce9ab-2c3f-4afe-b2b7-d4ac6d2199c8" />
      </body>
      <title>Static Classes / Extension Methods</title>
      <guid isPermaLink="false">http://www.programgood.net/PermaLink,guid,f60ce9ab-2c3f-4afe-b2b7-d4ac6d2199c8.aspx</guid>
      <link>http://www.programgood.net/2010/02/11/StaticClassesExtensionMethods.aspx</link>
      <pubDate>Thu, 11 Feb 2010 00:54:17 GMT</pubDate>
      <description>&lt;p&gt;
Static classes are usually used as ‘utility’ classes
&lt;/p&gt;
&lt;p&gt;
You don’t need an instance
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Program&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Main()&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;double&lt;/span&gt; result = thing.daveSubtract(10);&lt;br /&gt;
Console.WriteLine(result);&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; thing&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;double&lt;/span&gt; daveSubtract(&lt;span style="color: #0000ff"&gt;double&lt;/span&gt; number)&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;return&lt;/span&gt; (number - 2);&lt;br /&gt;
}&lt;br /&gt;
}&lt;/pre&gt;
&lt;/div&gt;
&lt;h3&gt;Extension Methods
&lt;/h3&gt;
&lt;p&gt;
From: http://msdn.microsoft.com/en-us/library/bb383977.aspx
&lt;/p&gt;
&lt;p&gt;
Extension methods enable you to &amp;quot;add&amp;quot; methods to existing types without
creating a new derived type,
&lt;/p&gt;
&lt;p&gt;
Extension methods are a special kind of static method, but they are called as if they
were instance methods on the extended type. 
&lt;/p&gt;
&lt;p&gt;
For client code, there is no apparent difference between calling an extension method
and the methods that are actually defined in a type.
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; ConsoleApplication1&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Program&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Main(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;[]
args)&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; s = &lt;span style="color: #006080"&gt;&amp;quot;hello
extension methods are good&amp;quot;&lt;/span&gt;;&lt;br /&gt;
Console.WriteLine(s);&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; i = s.WordCount();&lt;br /&gt;
Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;number of words is {0}&amp;quot;&lt;/span&gt;,
i.ToString());&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; MyExtensions&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; WordCount(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt; String
str)&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;return&lt;/span&gt; str.Split(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;span style="color: #0000ff"&gt;char&lt;/span&gt;[]
{ &lt;span style="color: #006080"&gt;' '&lt;/span&gt;, &lt;span style="color: #006080"&gt;'.'&lt;/span&gt;, &lt;span style="color: #006080"&gt;'?'&lt;/span&gt; },
StringSplitOptions.RemoveEmptyEntries).Length;&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
}&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=f60ce9ab-2c3f-4afe-b2b7-d4ac6d2199c8" /&gt;</description>
      <category>c# language</category>
    </item>
  </channel>
</rss>