<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://www.davidga.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><title type="html">David Gardner&amp;#39;s Snippets</title><subtitle type="html"> </subtitle><id>http://www.davidga.com/atom.aspx</id><link rel="alternate" type="text/html" href="http://www.davidga.com/default.aspx" /><link rel="self" type="application/atom+xml" href="http://www.davidga.com/atom.aspx" /><generator uri="http://communityserver.org" version="3.0.20611.960">Community Server</generator><updated>2006-10-03T11:05:00Z</updated><entry><title>Checked Keyword</title><link rel="alternate" type="text/html" href="http://www.davidga.com/archive/2008/03/04/sample-post.aspx" /><id>http://www.davidga.com/archive/2008/03/04/sample-post.aspx</id><published>2008-03-04T22:25:00Z</published><updated>2008-03-04T22:25:00Z</updated><content type="html">&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;</content><author><name>Dave</name><uri>http://www.davidga.com/members/Dave.aspx</uri></author></entry><entry><title>NET Framework 3.0</title><link rel="alternate" type="text/html" href="http://www.davidga.com/archive/2006/10/03/net-framework-3-0.aspx" /><id>http://www.davidga.com/archive/2006/10/03/net-framework-3-0.aspx</id><published>2006-10-03T10:05:00Z</published><updated>2006-10-03T10:05:00Z</updated><content type="html">&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;</content><author><name>admin</name><uri>http://www.davidga.com/members/admin.aspx</uri></author></entry></feed>