<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://www.davidga.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>David Gardner&amp;#39;s Snippets</title><link>http://www.davidga.com/default.aspx</link><description> </description><dc:language>en</dc:language><generator>CommunityServer 2007 SP2 (Build: 20611.960)</generator><item><title>Checked Keyword</title><link>http://www.davidga.com/archive/2008/03/04/sample-post.aspx</link><pubDate>Tue, 04 Mar 2008 22:25:00 GMT</pubDate><guid isPermaLink="false">50729125-946c-478f-b84e-cded85d9d48f:12</guid><dc:creator>Dave</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://www.davidga.com/rsscomments.aspx?PostID=12</wfw:commentRss><comments>http://www.davidga.com/archive/2008/03/04/sample-post.aspx#comments</comments><description>&lt;SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: 'Arial','sans-serif'"&gt;&lt;FONT face=Courier color=#000000&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: 'Arial','sans-serif'"&gt;&lt;FONT face=Calibri color=#000000 size=3&gt;&lt;SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Arial','sans-serif'"&gt;I recently discovered the “checked” keyword which is used to throw an exception when arithmetic overflow occurs. This is important as .net automatically narrows data types which could lead to overflow problems. The following example shows how this situation could arise:&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt; 
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT face=Courier&gt;class Program &lt;BR&gt;{ &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; static void Main(string[] args) &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; { &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int value1 = 100000; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int value2 = 200000; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Courier&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; short value3 = (short)Add(value1, value2); &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Courier&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Console.WriteLine(value3); &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Courier&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; static int Add(int x, int y) {&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return x + y; } &lt;BR&gt;}&lt;/FONT&gt;&lt;/P&gt;&lt;SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Arial','sans-serif'"&gt;&lt;SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Arial','sans-serif'"&gt;Note that this code will compile cleanly at appears to be valid. However, casting the Add result to a &lt;I&gt;short&lt;/I&gt; results in an overflow condition that will not be detected at run-time. This can be trapped by using the &lt;I&gt;checked&lt;/I&gt; keyword thus:&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt; 
&lt;P&gt;&lt;FONT face=Courier size=2&gt;class Program &lt;BR&gt;{ &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; static void Main(string[] args) &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; { &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int value1 = 100000; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int value2 = 200000; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Courier size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; short value3 = checked((short)Add(value1, value2)); &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Courier size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Console.WriteLine(value3); &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Courier size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; static int Add(int x, int y) {&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return x + y; } &lt;BR&gt;}&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://www.davidga.com/aggbug.aspx?PostID=12" width="1" height="1"&gt;</description></item><item><title>NET Framework 3.0</title><link>http://www.davidga.com/archive/2006/10/03/net-framework-3-0.aspx</link><pubDate>Tue, 03 Oct 2006 10:05:00 GMT</pubDate><guid isPermaLink="false">50729125-946c-478f-b84e-cded85d9d48f:5</guid><dc:creator>admin</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://www.davidga.com/rsscomments.aspx?PostID=5</wfw:commentRss><comments>http://www.davidga.com/archive/2006/10/03/net-framework-3-0.aspx#comments</comments><description>&lt;P&gt;I have had a couple of customers ask the question. What is in the .NET Framework 3.0 and why the off pattern release. Recently&amp;nbsp;Microsoft renamed the&amp;nbsp;WinFX to .NET Framework 3.0 this will be released in the Office/Vista timframe. We are currently at the RC1 release located at: &amp;nbsp;.NET Framework 3.0&lt;/P&gt;
&lt;P&gt;The included features of the NETFR3&amp;nbsp;are: &lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Windows Communication Foundation 
&lt;LI&gt;Windows Presentation Foundation 
&lt;LI&gt;Windows Workflow Foundation (Dub F) 
&lt;LI&gt;Windows CardSpace&lt;/LI&gt;&lt;/UL&gt;&lt;img src="http://www.davidga.com/aggbug.aspx?PostID=5" width="1" height="1"&gt;</description></item></channel></rss>