<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" gd:etag="W/&quot;A0cEQ3c6cCp7ImA9WxBbEU0.&quot;"><id>tag:blogger.com,1999:blog-996059265581647286</id><updated>2010-03-08T22:30:02.918-06:00</updated><title>Coding Light</title><subtitle type="html">Illuminated Ideas and Algorithms in Software</subtitle><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://blog.codinglight.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://blog.codinglight.com/" /><link rel="next" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default?start-index=26&amp;max-results=25&amp;redirect=false&amp;v=2" /><author><name>David Morton</name><uri>http://www.blogger.com/profile/04619192201221893142</uri><email>dvd.morton@gmail.com</email></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>92</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/CodingLight" /><feedburner:info uri="codinglight" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry gd:etag="W/&quot;CkMBQX4zcCp7ImA9WxBVFU4.&quot;"><id>tag:blogger.com,1999:blog-996059265581647286.post-717916461091870601</id><published>2010-02-18T15:57:00.002-06:00</published><updated>2010-02-18T16:00:50.088-06:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-02-18T16:00:50.088-06:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Deprecated" /><category scheme="http://www.blogger.com/atom/ns#" term="Collections" /><category scheme="http://www.blogger.com/atom/ns#" term="ArrayList" /><title>Should ArrayList Be Deprecated?</title><content type="html">I came across a poster on the Microsoft Forums the other day, who was asking a question about the .NET ArrayList. Whenever I hear the word, I cringe.  Since the advent of generics, I've &lt;span style="font-style:italic;"&gt;never once &lt;/span&gt;used ArrayList.&lt;br /&gt;&lt;br /&gt;That being said, some of you may have, so I'd like to hear what you think.  &lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Should ArrayList be deprecated, perhaps with a deprecation message that points the user to List&lt;t&gt;?&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Feel free to vote in the poll on the right, or leave your comments below. &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/996059265581647286-717916461091870601?l=blog.codinglight.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingLight/~4/WGcEnubLK9s" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.codinglight.com/feeds/717916461091870601/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=996059265581647286&amp;postID=717916461091870601&amp;isPopup=true" title="9 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/717916461091870601?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/717916461091870601?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CodingLight/~3/WGcEnubLK9s/should-arraylist-be-deprecated.html" title="Should ArrayList Be Deprecated?" /><author><name>David Morton</name><uri>http://www.blogger.com/profile/04619192201221893142</uri><email>dvd.morton@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="05004467602404035574" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">9</thr:total><feedburner:origLink>http://blog.codinglight.com/2010/02/should-arraylist-be-deprecated.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkAFRn0-fCp7ImA9WxBVE0k.&quot;"><id>tag:blogger.com,1999:blog-996059265581647286.post-918023719771889404</id><published>2010-02-16T13:29:00.004-06:00</published><updated>2010-02-16T13:31:57.354-06:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-02-16T13:31:57.354-06:00</app:edited><title>What's wrong with this picture?</title><content type="html">&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Collections.Generic;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Linq;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Text;&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; ConsoleApplication95&lt;br /&gt;{&lt;br /&gt;    &lt;span class="kwrd"&gt;class&lt;/span&gt; Program&lt;br /&gt;    {&lt;br /&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; List&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; _items = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;();&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; List&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; Items&lt;br /&gt;        {&lt;br /&gt;            get { &lt;span class="kwrd"&gt;return&lt;/span&gt; _items.ToList(); }&lt;br /&gt;            set { _items = &lt;span class="kwrd"&gt;value&lt;/span&gt;; }&lt;br /&gt;        }&lt;br /&gt;        &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main(&lt;span class="kwrd"&gt;string&lt;/span&gt;[] args)&lt;br /&gt;        {&lt;br /&gt;            Program program = &lt;span class="kwrd"&gt;new&lt;/span&gt; Program();&lt;br /&gt;            program.Items = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; { &lt;span class="str"&gt;"One"&lt;/span&gt;, &lt;span class="str"&gt;"Two"&lt;/span&gt;, &lt;span class="str"&gt;"Three"&lt;/span&gt; };&lt;br /&gt;            program.Items.Add(&lt;span class="str"&gt;"Four"&lt;/span&gt;);&lt;br /&gt;            &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (var item &lt;span class="kwrd"&gt;in&lt;/span&gt; program.Items)&lt;br /&gt;                Console.WriteLine(item);&lt;br /&gt;            Console.ReadLine();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;What do you think this code will do?&lt;br /&gt;&lt;br /&gt;It may not be what you think.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/996059265581647286-918023719771889404?l=blog.codinglight.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingLight/~4/zm5yCeiY9DY" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.codinglight.com/feeds/918023719771889404/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=996059265581647286&amp;postID=918023719771889404&amp;isPopup=true" title="4 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/918023719771889404?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/918023719771889404?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CodingLight/~3/zm5yCeiY9DY/whats-wrong-with-this-picture_16.html" title="What's wrong with this picture?" /><author><name>David Morton</name><uri>http://www.blogger.com/profile/04619192201221893142</uri><email>dvd.morton@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="05004467602404035574" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">4</thr:total><feedburner:origLink>http://blog.codinglight.com/2010/02/whats-wrong-with-this-picture_16.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Dk8HR3s5eCp7ImA9WxNVGUw.&quot;"><id>tag:blogger.com,1999:blog-996059265581647286.post-6872255634200890394</id><published>2009-10-29T17:52:00.010-05:00</published><updated>2009-10-30T10:00:36.520-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-10-30T10:00:36.520-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="dynamic" /><category scheme="http://www.blogger.com/atom/ns#" term="RuntimeBinderException" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="syntax" /><category scheme="http://www.blogger.com/atom/ns#" term="4.0" /><category scheme="http://www.blogger.com/atom/ns#" term="ExpandoObject" /><title>Scary Halloween-Style C# 4.0 Code</title><content type="html">Check out the following code:&lt;br /&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Dynamic;&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; ConsoleApplication9&lt;br /&gt;{&lt;br /&gt;    &lt;span class="kwrd"&gt;class&lt;/span&gt; Program&lt;br /&gt;    {&lt;br /&gt;        &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main(&lt;span class="kwrd"&gt;string&lt;/span&gt;[] args)&lt;br /&gt;        {&lt;br /&gt;            &lt;span class="kwrd"&gt;dynamic&lt;/span&gt; d = &lt;span class="kwrd"&gt;new&lt;/span&gt; ExpandoObject();&lt;br /&gt;            d.Hola = &lt;span class="str"&gt;"Howdy"&lt;/span&gt;;&lt;br /&gt;            SaySomething(d);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;void&lt;/span&gt; SaySomething(&lt;span class="kwrd"&gt;dynamic&lt;/span&gt; d)&lt;br /&gt;        {&lt;br /&gt;            Console.WriteLine(d.Hola);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;What do you think this code should do?  There's no static method to accept the incoming parameter, so compile error, right?&lt;br /&gt;&lt;br /&gt;Wrong. &lt;br /&gt;&lt;br /&gt;This compiles, but blows up at runtime with a RuntimeBinderException, not finding the instance method SaySomething. &lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_9JzvvMU7X2E/Sur_d7z3h7I/AAAAAAAAAVI/O8a1lNzQL3Y/s1600-h/RuntimeBinderException.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 223px;" src="http://3.bp.blogspot.com/_9JzvvMU7X2E/Sur_d7z3h7I/AAAAAAAAAVI/O8a1lNzQL3Y/s400/RuntimeBinderException.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5398407993093490610" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;While the above compiles just fine, the following does not:&lt;br /&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Dynamic;&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; ConsoleApplication9&lt;br /&gt;{&lt;br /&gt;    &lt;span class="kwrd"&gt;class&lt;/span&gt; Program&lt;br /&gt;    {&lt;br /&gt;        &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main(&lt;span class="kwrd"&gt;string&lt;/span&gt;[] args)&lt;br /&gt;        {&lt;br /&gt;            &lt;span class="kwrd"&gt;dynamic&lt;/span&gt; d = &lt;span class="kwrd"&gt;new&lt;/span&gt; ExpandoObject();&lt;br /&gt;            d.Hola = &lt;span class="str"&gt;"Howdy"&lt;/span&gt;;&lt;br /&gt;            SaySomething(d);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;Rightly recognizing that SaySomething doesn't exist in the current context.  &lt;br /&gt;&lt;br /&gt;This is the scariest thing I've seen all week.  And I was in Austin last weekend.  &lt;br /&gt;&lt;br /&gt;So why does it do this?  This goes back to the way that overload resolution is achieved during compilation.  &lt;a href="http://blogs.msdn.com/ericlippert/archive/2009/07/06/color-color.aspx"&gt;Eric Lippert wrote about this problem in C# 3.0&lt;/a&gt; earlier this year.  Overload resolution steps (for C# 3.0) are as follows, in this order:&lt;br /&gt;&lt;br /&gt;1. First, each overload is examined according to it's arguments. &lt;br /&gt;2. Next the determination of whether or not the overload is accessible from the current static or instance context is made.  &lt;br /&gt;3. If the overload selected from step 1 is inaccessible, then a compile-time error is thrown. &lt;br /&gt;&lt;br /&gt;Now, let's look at the situation I posed above.  The major difference here is &lt;span style="font-style:italic;"&gt;when&lt;/span&gt; this resolution occurs.  The first example actually compiles, because the overload resolution is delayed until runtime.  The order of operations, however, stays the same.  &lt;br /&gt;&lt;br /&gt;At runtime, these steps are performed in the following order:&lt;br /&gt;&lt;br /&gt;1. First, each overload is examined according to it's arguments.&lt;br /&gt;2. Next the determination of whether or not the overload is accessible from the current static or instance context is made. &lt;br /&gt;3. If the overload selected from step 1 is inaccessible, then a &lt;span style="font-style:italic;"&gt;run-time&lt;/span&gt; error is thrown. &lt;br /&gt;&lt;br /&gt;In other words, the rules are &lt;span style="font-style:italic;"&gt;exactly&lt;/span&gt; the same as they were in C# 3.0, but the consequences of this mistake while using dynamic are much more severe than they are when not using the dynamic type.&lt;br /&gt;&lt;br /&gt;All this to say, the dynamic type is a nice addition to the C# toolbox, but it needs to be used with &lt;span style="font-style:italic;"&gt;extreme&lt;/span&gt; care.  &lt;br /&gt;&lt;br /&gt;With great power comes great responsibility.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/996059265581647286-6872255634200890394?l=blog.codinglight.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingLight/~4/YfGeubYIJ6k" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.codinglight.com/feeds/6872255634200890394/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=996059265581647286&amp;postID=6872255634200890394&amp;isPopup=true" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/6872255634200890394?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/6872255634200890394?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CodingLight/~3/YfGeubYIJ6k/scary-halloween-style-c-40-code.html" title="Scary Halloween-Style C# 4.0 Code" /><author><name>David Morton</name><uri>http://www.blogger.com/profile/04619192201221893142</uri><email>dvd.morton@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="05004467602404035574" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/_9JzvvMU7X2E/Sur_d7z3h7I/AAAAAAAAAVI/O8a1lNzQL3Y/s72-c/RuntimeBinderException.png" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total><feedburner:origLink>http://blog.codinglight.com/2009/10/scary-halloween-style-c-40-code.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0ABQHg7eSp7ImA9WxNVFUg.&quot;"><id>tag:blogger.com,1999:blog-996059265581647286.post-6010476860570906555</id><published>2009-10-26T05:44:00.006-05:00</published><updated>2009-10-26T06:15:51.601-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-10-26T06:15:51.601-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="developer" /><category scheme="http://www.blogger.com/atom/ns#" term="information overload" /><category scheme="http://www.blogger.com/atom/ns#" term="social networks" /><title>A Better Developer</title><content type="html">We developers are constantly barraged with an overflow of activities and information we don't possibly have enough time for, and we're given very little guidance on what is and isn't worthwhile.  This morning on my drive to work, I was reflecting on some of the things I'm involved with, questioning the usefulness of each.  Some of these activities (other than the act of coding itself) include:&lt;br /&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;Using Twitter&lt;/li&gt;&lt;li&gt;Attending User Groups&lt;/li&gt;&lt;li&gt;Leading User Groups&lt;/li&gt;&lt;li&gt;Attending Conferences&lt;/li&gt;&lt;li&gt;Speaking at Conferences&lt;/li&gt;&lt;li&gt;Reading Books (of various kinds)&lt;/li&gt;&lt;li&gt;Writing Books&lt;/li&gt;&lt;li&gt;Participating in IRC&lt;/li&gt;&lt;li&gt;Contributing to Open-Source Projects&lt;/li&gt;&lt;li&gt;Taking Certification Tests&lt;/li&gt;&lt;li&gt;Contributing to Forums&lt;/li&gt;&lt;li&gt;Writing Blogs&lt;/li&gt;&lt;li&gt;Reading Blogs&lt;/li&gt;&lt;li&gt;LinkedIn&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;And that's just to name a few.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;Which ones are and aren't worthwhile to you is wholly dependent on your personality, affinity, and general life direction. &lt;br /&gt;&lt;br /&gt;There's a peer-pressure that comes with this (or any) industry to &lt;a href="http://sethgodin.typepad.com/seths_blog/2009/10/notice-me.html"&gt;be noticed&lt;/a&gt;, but ultimately, the question we, as developers, should all be asking is "does this make me a better developer?"  Answer that question, and you'll know what's worth giving your time to.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/996059265581647286-6010476860570906555?l=blog.codinglight.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingLight/~4/euYFTnNmnrs" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.codinglight.com/feeds/6010476860570906555/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=996059265581647286&amp;postID=6010476860570906555&amp;isPopup=true" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/6010476860570906555?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/6010476860570906555?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CodingLight/~3/euYFTnNmnrs/better-developer.html" title="A Better Developer" /><author><name>David Morton</name><uri>http://www.blogger.com/profile/04619192201221893142</uri><email>dvd.morton@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="05004467602404035574" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total><feedburner:origLink>http://blog.codinglight.com/2009/10/better-developer.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEEBQX48cSp7ImA9WxNVEU4.&quot;"><id>tag:blogger.com,1999:blog-996059265581647286.post-4813210944893345844</id><published>2009-10-21T09:13:00.001-05:00</published><updated>2009-10-21T09:50:50.079-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-10-21T09:50:50.079-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="office" /><category scheme="http://www.blogger.com/atom/ns#" term="interop" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="4.0" /><title>Adventures in Office Interop and C# 4.0</title><content type="html">I had a chance earlier to play with the new features introduced to C# 4.0 for the support of Office Interop.  There are a couple of notable features.  &lt;br /&gt;&lt;br /&gt;First, Type.Missing is no longer required to pass into COM calls.  This means no more:&lt;br /&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;wbs.Open(&lt;span class="str"&gt;@"somefile.xlsx"&lt;/span&gt;, missing, missing, missing, &lt;br /&gt;                           missing, missing, missing, &lt;br /&gt;                           missing, missing, missing,&lt;br /&gt;                           missing, missing, missing, &lt;br /&gt;                           missing, missing);&lt;/pre&gt;&lt;br /&gt;Instead you can opt for:&lt;br /&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;wbs.Open(&lt;span class="str"&gt;@"somefile.xlsx"&lt;/span&gt;);&lt;/pre&gt;&lt;br /&gt;Readability FTW!&lt;br /&gt;&lt;br /&gt;Other changes include the ability to use the indexed methods ("get_Range" for example) using indexers.  Now, instead of:&lt;br /&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;Range range = ws.get_Range(&lt;span class="str"&gt;"A1"&lt;/span&gt;, &lt;span class="str"&gt;"A1"&lt;/span&gt;);&lt;/pre&gt;&lt;br /&gt;You can use:&lt;br /&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;Range range = ws.Range[&lt;span class="str"&gt;"A1"&lt;/span&gt;];&lt;/pre&gt;&lt;br /&gt;Combined with the optional parameters, this makes for another win for readability.  &lt;br /&gt;&lt;br /&gt;In some situations, this "inferred property" addition makes things even more readable.  How many times when setting a value in Excel Interop have you done this:&lt;br /&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;range.set_Value(XlRangeValueDataType.xlRangeValueDefault, i);&lt;/pre&gt;&lt;br /&gt;Yeah, not too pretty.  Try this on instead:&lt;br /&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;range.Value = i;&lt;/pre&gt;&lt;br /&gt;Uh-huh.  Yep.  Much, &lt;span style="font-style:italic;"&gt;much&lt;/span&gt; more readable. &lt;br /&gt;&lt;br /&gt;That is all.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/996059265581647286-4813210944893345844?l=blog.codinglight.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingLight/~4/ClrvX7xagTU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.codinglight.com/feeds/4813210944893345844/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=996059265581647286&amp;postID=4813210944893345844&amp;isPopup=true" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/4813210944893345844?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/4813210944893345844?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CodingLight/~3/ClrvX7xagTU/adventures-in-office-interop-and-net-40.html" title="Adventures in Office Interop and C# 4.0" /><author><name>David Morton</name><uri>http://www.blogger.com/profile/04619192201221893142</uri><email>dvd.morton@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="05004467602404035574" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total><feedburner:origLink>http://blog.codinglight.com/2009/10/adventures-in-office-interop-and-net-40.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D04FSHw_eip7ImA9WxNWGUQ.&quot;"><id>tag:blogger.com,1999:blog-996059265581647286.post-9011220897460957724</id><published>2009-10-19T18:08:00.006-05:00</published><updated>2009-10-19T18:45:19.242-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-10-19T18:45:19.242-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="CompiledNameAttribute" /><category scheme="http://www.blogger.com/atom/ns#" term="polyglot" /><category scheme="http://www.blogger.com/atom/ns#" term="F#" /><category scheme="http://www.blogger.com/atom/ns#" term="CompiledName" /><title>Be a Better Polyglot with F#'s CompiledNameAttribute</title><content type="html">F# introduces the CompiledNameAttribute with the October 2009 CTP.  This attribute provides a way to specify the compiled name of a method or type written in F#.  The big advantage here is the ability to prevent having to compromise on your naming schemes in either F# or any other language.  Internally to the assembly, you can still use the names you give to the constructs when you define the construct.  Externally, however, the name will be compiled into a ".NET Friendly" name, which you can specify using the CompiledNameAttribute.  &lt;br /&gt;&lt;br /&gt;Take, for example, the extension method I wrote in my previous post.  Using the CompiledNameAttribute, I can refer to this in F# using one name, and in C# using another name. &lt;br /&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;[&amp;lt;System.Runtime.CompilerServices.ExtensionAttribute&amp;gt;]&lt;br /&gt;module &lt;span class="kwrd"&gt;public&lt;/span&gt; Morton.Extensions.EnumerableExtensions&lt;br /&gt;       [&amp;lt;Microsoft.FSharp.Core.CompiledNameAttribute(&lt;span class="str"&gt;"OutputAll"&lt;/span&gt;)&amp;gt;]&lt;br /&gt;       [&amp;lt;System.Runtime.CompilerServices.ExtensionAttribute&amp;gt;]&lt;br /&gt;       let internalNameGoesHereForOutputting (_this:System.Collections.Generic.IEnumerable&amp;lt;'T&amp;gt;) = &lt;br /&gt;            &lt;span class="kwrd"&gt;for&lt;/span&gt; x &lt;span class="kwrd"&gt;in&lt;/span&gt; _this &lt;span class="kwrd"&gt;do&lt;/span&gt; System.Console.WriteLine x |&amp;gt; ignore&lt;br /&gt;       &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Note the internal name here is "internalNameGoesHereForOutputting" while the external name will be "OutputAll".  &lt;br /&gt;&lt;br /&gt;This is a very nice feature indeed, and I'd love to see it implemented in other languages as well.  Kudos to Don Syme and the rest of the F# team for this one.  This is an excellent step towards polyglot programming: translation.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/996059265581647286-9011220897460957724?l=blog.codinglight.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingLight/~4/pGuzfLtQEOg" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.codinglight.com/feeds/9011220897460957724/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=996059265581647286&amp;postID=9011220897460957724&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/9011220897460957724?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/9011220897460957724?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CodingLight/~3/pGuzfLtQEOg/be-better-polyglot-with-fs.html" title="Be a Better Polyglot with F#'s CompiledNameAttribute" /><author><name>David Morton</name><uri>http://www.blogger.com/profile/04619192201221893142</uri><email>dvd.morton@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="05004467602404035574" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://blog.codinglight.com/2009/10/be-better-polyglot-with-fs.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkAHQH48fyp7ImA9WxNVGUw.&quot;"><id>tag:blogger.com,1999:blog-996059265581647286.post-7910498087679910919</id><published>2009-10-19T17:43:00.007-05:00</published><updated>2009-10-30T09:58:51.077-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-10-30T09:58:51.077-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="F#" /><category scheme="http://www.blogger.com/atom/ns#" term="extension methods" /><title>Writing Extension Methods in F# to Use in C#</title><content type="html">F#, in my mind, is the language of implementation.  It provides a concise syntax when writing code "in the small" that is in many ways superior to C#.  This makes F# the ideal language for writing extension methods and other methods that perform operations that are frequently repeated.  &lt;br /&gt;&lt;br /&gt;Here's a small example on how to write an extension method in F# that takes a generic IEnumerable&amp;lt;T&amp;gt; and outputs each value to the console:&lt;br /&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;[&amp;lt;System.Runtime.CompilerServices.ExtensionAttribute&amp;gt;]&lt;br /&gt;module &lt;span class="kwrd"&gt;public&lt;/span&gt; Morton.Extensions.EnumerableExtensions&lt;br /&gt;       [&amp;lt;System.Runtime.CompilerServices.ExtensionAttribute&amp;gt;]&lt;br /&gt;       let OutputAll (_this:System.Collections.Generic.IEnumerable&amp;lt;'T&amp;gt;) = &lt;br /&gt;            &lt;span class="kwrd"&gt;for&lt;/span&gt; x &lt;span class="kwrd"&gt;in&lt;/span&gt; _this &lt;span class="kwrd"&gt;do&lt;/span&gt; System.Console.WriteLine x |&amp;gt; ignore&lt;/pre&gt;&lt;br /&gt;Note the use of the ExtensionAttribute on both the module declaration and on the function declaration.  Both of these are necessary to create the extension method. &lt;br /&gt;&lt;br /&gt;In C#, this code could be called just like any other Extension method.  First, add the proper using statements to your code, then call the method from any applicable type. &lt;br /&gt;&lt;br /&gt;The following code compiles and works properly when referencing an F# assembly containing the above function:&lt;br /&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Collections.Generic;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; Morton.Extensions;&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; ConsoleApplication1&lt;br /&gt;{&lt;br /&gt;    &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Program&lt;br /&gt;    {&lt;br /&gt;        &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main(&lt;span class="kwrd"&gt;string&lt;/span&gt;[] args)&lt;br /&gt;        {&lt;br /&gt;            List&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; list = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;();&lt;br /&gt;            list.Add(&lt;span class="str"&gt;"David"&lt;/span&gt;);&lt;br /&gt;            list.Add(&lt;span class="str"&gt;"Jennifer"&lt;/span&gt;);&lt;br /&gt;            list.OutputAll();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now we're cooking.  I could see myself using F# for tons of utility methods where writing it in C# would simply be too cumbersome.&lt;br /&gt;&lt;br /&gt;UPDATE (10/30/2009)&lt;br /&gt;&lt;br /&gt;I received a question today asking how these extensions could also be used from F# as well, with the same syntax.  It's not too difficult, but it does require a tiny bit of additional work.  The final code would look something like this:&lt;br /&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;[&amp;lt;System.Runtime.CompilerServices.ExtensionAttribute&amp;gt;]&lt;br /&gt;module &lt;span class="kwrd"&gt;public&lt;/span&gt; Morton.Extensions.EnumerableExtensions&lt;br /&gt;       [&amp;lt;System.Runtime.CompilerServices.ExtensionAttribute&amp;gt;]&lt;br /&gt;       let OutputAll (_this:System.Collections.Generic.IEnumerable&amp;lt;'T&amp;gt;) = &lt;br /&gt;            &lt;span class="kwrd"&gt;for&lt;/span&gt; x &lt;span class="kwrd"&gt;in&lt;/span&gt; _this &lt;span class="kwrd"&gt;do&lt;/span&gt; System.Console.WriteLine x |&amp;gt; ignore   &lt;br /&gt;&lt;br /&gt;       type System.Collections.Generic.IEnumerable&amp;lt;'T&amp;gt; with    &lt;br /&gt;            member &lt;span class="kwrd"&gt;this&lt;/span&gt;.OutputAll() = &lt;span class="kwrd"&gt;this&lt;/span&gt; |&amp;gt; OutputAll&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/996059265581647286-7910498087679910919?l=blog.codinglight.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingLight/~4/SmLUksG2ahE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.codinglight.com/feeds/7910498087679910919/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=996059265581647286&amp;postID=7910498087679910919&amp;isPopup=true" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/7910498087679910919?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/7910498087679910919?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CodingLight/~3/SmLUksG2ahE/writing-extension-methods-in-f-to-use.html" title="Writing Extension Methods in F# to Use in C#" /><author><name>David Morton</name><uri>http://www.blogger.com/profile/04619192201221893142</uri><email>dvd.morton@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="05004467602404035574" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total><feedburner:origLink>http://blog.codinglight.com/2009/10/writing-extension-methods-in-f-to-use.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0AHSH0yeip7ImA9WxNWE0g.&quot;"><id>tag:blogger.com,1999:blog-996059265581647286.post-8232578110279105028</id><published>2009-10-12T06:16:00.006-05:00</published><updated>2009-10-12T08:55:39.392-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-10-12T08:55:39.392-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Team" /><category scheme="http://www.blogger.com/atom/ns#" term="Character" /><category scheme="http://www.blogger.com/atom/ns#" term="Teachability" /><title>On Teachability in Team Development</title><content type="html">EDIT: Note that the terms "architect" and "developer" below are used loosely.  This post deals most directly with the teachability of a specific team member, whether that team member is an architect, developer, tester, etc.  This post assumes that the teacher, regardless of his role, is competent in teaching.  The architect/developer dichotomy below is use purely as a convenience to the purpose of the post. &lt;br /&gt;&lt;br /&gt;Software craftsmanship is more than just a set of intellectual know-how. Character traits also affect your ability to do the job.  The biggest barrier I see to excellent programming is often a lack of teachability.  It doesn't matter how smooth the software architecture is; if the developer can't or won't learn the architecture, it's of no use - the architecture will go by the wayside.  &lt;br /&gt;&lt;br /&gt;So in that vein, here are the top few barriers to teachability that I've seen:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Arrogance&lt;/span&gt; - The arrogant developer always has a better way, and his way is never wrong.  He'll fail to be teachable, because he already believes he knows it all.  According to him, his code is perfect, so he spends most of his time blaming others or outside factors for bugs that show up.  He'll never implement an architecture properly, because the architecture, in his opinion, is not as good as he could have made it.  Sadly, the arrogant developer was teachable at one point, but his success made him arrogant and he lost his ability to learn. &lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Laziness&lt;/span&gt; - A certain amount of laziness is a wonderful trait for a developer to have.  It's this laziness that makes a developer say "There's gotta be a better way".  Unbridled laziness, however, ignores the architecture "because it's too much work".  It's not that he &lt;span style="font-style:italic;"&gt;can't&lt;/span&gt; learn it, it's that he doesn't want to, and ugly code ensues. &lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Ability&lt;/span&gt; - Sadly, through no fault of their own, there are those developers that simply lack the ability to think logically, which is a needed trait for a developer.  I don't believe that anyone can program, just as I don't believe that everyone can sell or perform scientific research or manage people.  Different people have different strengths.  Typically people who are not teachable in one thing are often teachable in another.  These people should be encouraged to find those areas in which they excel. Luckily, these people are typically filtered out early on.  &lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Apathy&lt;/span&gt; - This is related to laziness, but this developer isn't lazy - he's tired.  He may be worn out on a particular project or with a particular technology, and he just doesn't care enough anymore to implement excellence.  &lt;br /&gt;&lt;br /&gt;In any of these situations, it's important to keep the team fresh.  An infusion of new blood can often help to renew the team and make it into something vibrant again.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/996059265581647286-8232578110279105028?l=blog.codinglight.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingLight/~4/nAxTWcjJZXw" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.codinglight.com/feeds/8232578110279105028/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=996059265581647286&amp;postID=8232578110279105028&amp;isPopup=true" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/8232578110279105028?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/8232578110279105028?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CodingLight/~3/nAxTWcjJZXw/on-teachability-in-team-development.html" title="On Teachability in Team Development" /><author><name>David Morton</name><uri>http://www.blogger.com/profile/04619192201221893142</uri><email>dvd.morton@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="05004467602404035574" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total><feedburner:origLink>http://blog.codinglight.com/2009/10/on-teachability-in-team-development.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0QGSX89eSp7ImA9WxNWEU0.&quot;"><id>tag:blogger.com,1999:blog-996059265581647286.post-8587888089896971883</id><published>2009-10-09T10:30:00.008-05:00</published><updated>2009-10-09T11:22:08.161-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-10-09T11:22:08.161-05:00</app:edited><title>Closures in C#</title><content type="html">LINQ has alot of "gotchas".  Take the following code, for example:&lt;br /&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; ConsoleApplication50&lt;br /&gt;{&lt;br /&gt;    &lt;span class="kwrd"&gt;class&lt;/span&gt; Program&lt;br /&gt;    {&lt;br /&gt;        &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main(&lt;span class="kwrd"&gt;string&lt;/span&gt;[] args)&lt;br /&gt;        {&lt;br /&gt;            &lt;span class="kwrd"&gt;int&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt; = 100;&lt;br /&gt;            Action&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; curriedAction = &lt;br /&gt;                x =&amp;gt; Console.WriteLine(x * &lt;span class="kwrd"&gt;value&lt;/span&gt;); &lt;br /&gt;            curriedAction(5);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;How does C# handle closures?  Let's take a closer look.  Here's the IL for the Main method:&lt;br /&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;.method &lt;span class="kwrd"&gt;private&lt;/span&gt; hidebysig &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main(&lt;span class="kwrd"&gt;string&lt;/span&gt;[] args) cil managed&lt;br /&gt;{&lt;br /&gt;    .entrypoint&lt;br /&gt;    .maxstack 3&lt;br /&gt;    .locals init (&lt;br /&gt;        [0] &lt;span class="kwrd"&gt;class&lt;/span&gt; ConsoleApplication50.Program/&amp;lt;&amp;gt;c__DisplayClass1 CS$&amp;lt;&amp;gt;8__locals2)&lt;br /&gt;    L_0000: newobj instance &lt;span class="kwrd"&gt;void&lt;/span&gt; ConsoleApplication50.Program/&amp;lt;&amp;gt;c__DisplayClass1::.ctor()&lt;br /&gt;    L_0005: stloc.0 &lt;br /&gt;    L_0006: ldloc.0 &lt;br /&gt;    L_0007: ldc.i4.s 100&lt;br /&gt;    L_0009: stfld int32 ConsoleApplication50.Program/&amp;lt;&amp;gt;c__DisplayClass1::&lt;span class="kwrd"&gt;value&lt;/span&gt;&lt;br /&gt;    L_000e: ldloc.0 &lt;br /&gt;    L_000f: ldftn instance &lt;span class="kwrd"&gt;void&lt;/span&gt; ConsoleApplication50.Program/&amp;lt;&amp;gt;c__DisplayClass1::&amp;lt;Main&amp;gt;b__0(int32)&lt;br /&gt;    L_0015: newobj instance &lt;span class="kwrd"&gt;void&lt;/span&gt; [mscorlib]System.Action`1&amp;lt;int32&amp;gt;::.ctor(&lt;span class="kwrd"&gt;object&lt;/span&gt;, native &lt;span class="kwrd"&gt;int&lt;/span&gt;)&lt;br /&gt;    L_001a: pop &lt;br /&gt;    L_001b: ldloc.0 &lt;br /&gt;    L_001c: ldc.i4 200&lt;br /&gt;    L_0021: stfld int32 ConsoleApplication50.Program/&amp;lt;&amp;gt;c__DisplayClass1::&lt;span class="kwrd"&gt;value&lt;/span&gt;&lt;br /&gt;    L_0026: ret &lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;Look at the locals declaration:&lt;br /&gt;&lt;pre class="csharpcode"&gt; .locals init (&lt;br /&gt;        [0] class ConsoleApplication50.Program/&lt;&gt;c__DisplayClass1 CS$&lt;&gt;8__locals2) &lt;/pre&gt;&lt;br /&gt;Looks like there's a whole lot more happening here than I originally intended.  Instead of having a local integer variable, I'm spinning up a whole class simply to hold my single integer variable.  In fact, there is &lt;span style="font-style:italic;"&gt;no&lt;/span&gt; local integer variable in this method.  It's this local &lt;&gt;c_DisplayClass1 instance that actually hosts the integer within it.  &lt;br /&gt;&lt;br /&gt;Also contained within this DisplayClass1 class is my delegate, which isn't just a static method at this point, it's an instance method.  &lt;br /&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; &amp;lt;Main&amp;gt;b__0(&lt;span class="kwrd"&gt;int&lt;/span&gt; x)&lt;br /&gt;{&lt;br /&gt;    Console.WriteLine((&lt;span class="kwrd"&gt;int&lt;/span&gt;) (x * &lt;span class="kwrd"&gt;this&lt;/span&gt;.&lt;span class="kwrd"&gt;value&lt;/span&gt;));&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;Interestingly, you can even view the variable for the target by calling the Target property of the curriedAction variable.  If I add the following two lines to this method:&lt;br /&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;var target = curriedAction.Target;&lt;br /&gt;Console.WriteLine(curriedAction.Target);&lt;br /&gt;Console.WriteLine(target.GetType().GetField(&lt;span class="str"&gt;"value"&lt;/span&gt;).GetValue(target));&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;I get this as part of the output:&lt;br /&gt;&lt;pre class="csharpcode"&gt;ConsoleApplication50.Program+&amp;lt;&amp;gt;__DisplayClass1&lt;br /&gt;100&lt;/pre&gt;&lt;br /&gt;So it appears that in situations where there is no closure, the compiler favors a static method, and in situations where there is a closure, the compiler favors an instance method on a compiler-generated class. &lt;br /&gt;&lt;br /&gt;I've heard people complain about LINQ's performance versus a for or a foreach loop, and I wouldn't be surprised if this has something to do with it.  Remember, each instantiated class will have to be collected at some point.  All in all, I'd say to avoid using closures wherever possible whenever performance is an issue.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/996059265581647286-8587888089896971883?l=blog.codinglight.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingLight/~4/AUonTs-T-Q0" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.codinglight.com/feeds/8587888089896971883/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=996059265581647286&amp;postID=8587888089896971883&amp;isPopup=true" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/8587888089896971883?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/8587888089896971883?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CodingLight/~3/AUonTs-T-Q0/closures-in-c.html" title="Closures in C#" /><author><name>David Morton</name><uri>http://www.blogger.com/profile/04619192201221893142</uri><email>dvd.morton@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="05004467602404035574" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total><feedburner:origLink>http://blog.codinglight.com/2009/10/closures-in-c.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0UDQXkzcSp7ImA9WxNWEEw.&quot;"><id>tag:blogger.com,1999:blog-996059265581647286.post-7344693215014455796</id><published>2009-10-08T09:06:00.008-05:00</published><updated>2009-10-08T09:14:30.789-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-10-08T09:14:30.789-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="design" /><category scheme="http://www.blogger.com/atom/ns#" term="user interface" /><title>User Interface Basics: Don't Taunt Your Users</title><content type="html">The setup was taking a while so I moved on to other things.  Which button do you think I wanted to press?&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_9JzvvMU7X2E/Ss3yFif9iHI/AAAAAAAAAUI/y_VEKVjpRFE/s1600-h/RestartNowNoChoice.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 375px; height: 165px;" src="http://3.bp.blogspot.com/_9JzvvMU7X2E/Ss3yFif9iHI/AAAAAAAAAUI/y_VEKVjpRFE/s400/RestartNowNoChoice.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5390230506006481010" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/996059265581647286-7344693215014455796?l=blog.codinglight.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingLight/~4/8TU14Q1LrT8" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.codinglight.com/feeds/7344693215014455796/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=996059265581647286&amp;postID=7344693215014455796&amp;isPopup=true" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/7344693215014455796?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/7344693215014455796?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CodingLight/~3/8TU14Q1LrT8/user-interface-basics-dont-taunt-your.html" title="User Interface Basics: Don't Taunt Your Users" /><author><name>David Morton</name><uri>http://www.blogger.com/profile/04619192201221893142</uri><email>dvd.morton@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="05004467602404035574" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/_9JzvvMU7X2E/Ss3yFif9iHI/AAAAAAAAAUI/y_VEKVjpRFE/s72-c/RestartNowNoChoice.jpg" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total><feedburner:origLink>http://blog.codinglight.com/2009/10/user-interface-basics-dont-taunt-your.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkIFRn48fip7ImA9WxNXGU4.&quot;"><id>tag:blogger.com,1999:blog-996059265581647286.post-3636180323264427773</id><published>2009-10-07T12:44:00.003-05:00</published><updated>2009-10-07T13:01:57.076-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-10-07T13:01:57.076-05:00</app:edited><title>Covariance and the "ref" Keyword.</title><content type="html">Here's a slight little detail worth noting.&lt;br /&gt;&lt;br /&gt;If you're passing a value into a method that uses the "ref" keyword, the type of the variable passed &lt;span style="font-style:italic;"&gt;must&lt;/span&gt; match the ref parameter &lt;span style="font-style:italic;"&gt;exactly&lt;/span&gt;. &lt;br /&gt;&lt;br /&gt;The value passed into the ref method is reassigned upon the method's completion, so the object reassigned must match the variable's declared type.  If a variable's type is only &lt;span style="font-style:italic;"&gt;derived&lt;/span&gt; from the parameter type requested by the method, there would be nothing stopping the method from reassigning the ref parameter internally thus causing a type mismatch on the method's completion.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/996059265581647286-3636180323264427773?l=blog.codinglight.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingLight/~4/PCn9va4N0oM" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.codinglight.com/feeds/3636180323264427773/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=996059265581647286&amp;postID=3636180323264427773&amp;isPopup=true" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/3636180323264427773?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/3636180323264427773?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CodingLight/~3/PCn9va4N0oM/covariance-and-ref-keyword.html" title="Covariance and the &quot;ref&quot; Keyword." /><author><name>David Morton</name><uri>http://www.blogger.com/profile/04619192201221893142</uri><email>dvd.morton@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="05004467602404035574" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total><feedburner:origLink>http://blog.codinglight.com/2009/10/covariance-and-ref-keyword.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0cFQHs8fyp7ImA9WxNXF0g.&quot;"><id>tag:blogger.com,1999:blog-996059265581647286.post-6879963730706613484</id><published>2009-10-05T09:53:00.003-05:00</published><updated>2009-10-05T10:03:31.577-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-10-05T10:03:31.577-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="blogging" /><title>On Blogging</title><content type="html">I find my Google Reader queue fills up very quickly, and it's a rare situation in which I'm actually interested in reading most of the blogs I've added there.  I find myself repeatedly attracted to the non-technical blogs, such as Seth Godin's blog.  In all honesty, the technical blogs bore me after a while.  I suppose my thought process goes something like this: "If I don't need to know about something right now, then why am I spending my time reading it?" &lt;br /&gt;&lt;br /&gt;I think both are important, but I'm beginning to think that the technical blogs are good material for search engines, while the non-technical ones are the ones I really want to read on a daily basis.  I only read the technical ones when I'm trying to figure out the details on exactly how to perform a task, while the non-technical ones really encourage me towards excellence in my craft.  &lt;br /&gt;&lt;br /&gt;I'm curious to know how many of you would say the majority of the blogs you follow are highly technical, and how many are less technical, but no less relevant, being applicable to more general aspects of your job.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/996059265581647286-6879963730706613484?l=blog.codinglight.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingLight/~4/dtrxzGfkJk0" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.codinglight.com/feeds/6879963730706613484/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=996059265581647286&amp;postID=6879963730706613484&amp;isPopup=true" title="3 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/6879963730706613484?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/6879963730706613484?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CodingLight/~3/dtrxzGfkJk0/on-blogging.html" title="On Blogging" /><author><name>David Morton</name><uri>http://www.blogger.com/profile/04619192201221893142</uri><email>dvd.morton@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="05004467602404035574" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">3</thr:total><feedburner:origLink>http://blog.codinglight.com/2009/10/on-blogging.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEcCQHg6fip7ImA9WxNRFUw.&quot;"><id>tag:blogger.com,1999:blog-996059265581647286.post-5160912168410985378</id><published>2009-09-09T10:55:00.004-05:00</published><updated>2009-09-09T11:01:01.616-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-09-09T11:01:01.616-05:00</app:edited><title>Windows Internals Review - Part 1</title><content type="html">&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.amazon.com/Windows®-Internals-Including-Windows-PRO-Developer/dp/0735625301"&gt;&lt;img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 107px; height: 139px;" src="http://4.bp.blogspot.com/_9JzvvMU7X2E/SqfRBhZ4qBI/AAAAAAAAATQ/p5kKYoR3-y0/s400/bb963901.Book5thEd(en-us,MSDN.10).png" border="0" alt=""id="BLOGGER_PHOTO_ID_5379498103994361874" /&gt;&lt;/a&gt;I know I've been a bit "radio silent" lately.  I've been reading through Windows Internals by Russinovich and Solomon, for a review I'm doing for Microsoft Press.  I'm pleased to say that the first part of this review is up now on the Microsoft Press Blog, and you can read it &lt;a href="http://blogs.msdn.com/microsoft_press/archive/2009/09/09/reader-review-windows-internals-fifth-edition.aspx"&gt;here&lt;/a&gt;.  Over the next couple of months, I anticipate that the majority of my time spent outside of work will be spent reading this particular book and working on subsequent reviews of it.  It's an excellent book, and I'm learning a tremendous amount of information from it.  If you're even slightly interested in what goes on behind the scenes in Windows, I would highly recommend this book.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/996059265581647286-5160912168410985378?l=blog.codinglight.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingLight/~4/dw3yWbrvy5c" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.codinglight.com/feeds/5160912168410985378/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=996059265581647286&amp;postID=5160912168410985378&amp;isPopup=true" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/5160912168410985378?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/5160912168410985378?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CodingLight/~3/dw3yWbrvy5c/windows-internals-review-part-1.html" title="Windows Internals Review - Part 1" /><author><name>David Morton</name><uri>http://www.blogger.com/profile/04619192201221893142</uri><email>dvd.morton@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="05004467602404035574" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/_9JzvvMU7X2E/SqfRBhZ4qBI/AAAAAAAAATQ/p5kKYoR3-y0/s72-c/bb963901.Book5thEd(en-us,MSDN.10).png" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total><feedburner:origLink>http://blog.codinglight.com/2009/09/windows-internals-review-part-1.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUEEQns7fip7ImA9WxNSF08.&quot;"><id>tag:blogger.com,1999:blog-996059265581647286.post-873517937874027487</id><published>2009-08-31T08:00:00.000-05:00</published><updated>2009-08-31T08:00:03.506-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-08-31T08:00:03.506-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET" /><category scheme="http://www.blogger.com/atom/ns#" term="Updated" /><category scheme="http://www.blogger.com/atom/ns#" term="Instance" /><category scheme="http://www.blogger.com/atom/ns#" term="ObjectContainerDataSource" /><title>On the Evils of ObjectContainerDataSource with MVP Pattern</title><content type="html">Oh my head is hurting after banging it against the wall for a while now.  I've been working with the &lt;a href="http://websf.codeplex.com/"&gt;Web Client Software Factory&lt;/a&gt;, and started using the &lt;a href="http://msdn.microsoft.com/en-us/library/cc304698.aspx"&gt;ObjectContainerDataSource&lt;/a&gt; class to try to bind some of our model to the view.  All was going well, until I found the fine print from the &lt;a href="http://msdn.microsoft.com/en-us/library/cc304832.aspx"&gt;How to page&lt;/a&gt; on the ObjectContainerDataSource.  That's when I started becoming very angry. &lt;br /&gt;&lt;br /&gt;Here's the fine print:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;Instance. This is the data object. The ObjectContainerDataSource control uses reflection to create this object (on every update operation, delete operation, and insert operation) and populates it with the input data from the data-bound control.&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Huh?  &lt;br /&gt;&lt;br /&gt;Why on this green ball on which I sit would I want a reconstituted object populated with &lt;span style="font-style:italic;"&gt;only the data that was bound to the form?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Don't they understand that there might be more data here I want to maintain?  The issue, as far as I can tell, is that the MVP pattern is expecting that the object you bind to the UI will have absolutely nothing but the specific properties that show up on a FormView.  This isn't true.  I might want to reuse the same object (staying &lt;a href="http://en.wikipedia.org/wiki/Don't_repeat_yourself"&gt;DRY&lt;/A&gt; and enabling object reuse.  Somehow, I gotta use the same object, so I have a few options:&lt;br /&gt;&lt;br /&gt;1. When I hit the point of updating the object, ignore the instance that the ObjectContainerDataSource creates, and simply fetch the old object from the services, checking each property (perhaps via reflection) and setting the properties that have changed onto the object in question.  This is obviously a bad idea for several reasons.  First of all, that means I'm going to have to make another call to the database, adding more time to the update.  I don't want to do that.  Also, I'm going to have to write some funky reflection code to compare all the values.  This is more work than it's worth. &lt;br /&gt;&lt;br /&gt;2. Store the object in state, and retrieve it.  That's a nice idea, but what if this whole MVP pattern is being implemented on a user control and I'm planning on having more than one of these controls on a specific page?  That won't work either, as the instances will overwrite one another. &lt;br /&gt;&lt;br /&gt;3. Completely and totally override the ObjectContainerDataSource and ObjectContainerDataSourceView and make a new one.  &lt;a href="http://websf.codeplex.com/Thread/View.aspx?ThreadId=67047"&gt;One desperate programmer has already tried this&lt;/a&gt; and I nearly did too, but I felt the solution was a little bit bloated for my needs.  Again.  I'm lazy. &lt;br /&gt;&lt;br /&gt;4. Drop the whole thing, fetch the items from the database, and manually set the value from each and every field in the FormView to the object.  Nah.  Not gonna do that.  &lt;br /&gt;&lt;br /&gt;So what was the solution I came up with?  I'm sure most of you are hanging on the edge of your seats with bated breath.  &lt;br /&gt;&lt;br /&gt;I ignored the entire Updated event entirely.  &lt;br /&gt;&lt;br /&gt;Here's why.  The Updated Event comes with the ObjectContainerDataSourceStatusEventArgsobject, while the &lt;span style="font-style:italic;"&gt;Updating&lt;/span&gt; event comes with the ObjectContainerDataSourceUpdatingEventArgs object, both of which would make &lt;a href="http://www.stevemcconnell.com/"&gt;Steve McConnell&lt;/a&gt; choke because of their names.  Nevertheless, they're very different objects.  &lt;br /&gt;&lt;br /&gt;The ObjectContainerDataSourceStatusEventArgs provides two properties: Instance, and AffectedRows.  Instance is the reconstituted (regurgitated?) version of the bound object, while AffectedRows tells you how many fields the user changed before he/she submitted.  Yeah, both of those are pretty useless. &lt;br /&gt;&lt;br /&gt;Contrast that with the Updating event.  The Updating event offers you the Keys property, and the NewValues and OldValues Dictionaries, along with the Cancel property to cancel the update altogether.  Ahh, now we can determine &lt;span style="font-style:italic;"&gt;exactly what's changed&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;Now, buried deep in the framework is a type I found while hunting around called the &lt;br /&gt;TypeDescriptionHelper.  This class is the right to ObjectContainerDataSource's wrong.  &lt;br /&gt;&lt;br /&gt;On TypeDescriptionHelper, there's a poorly named, but very useful method called BuildInstance, which takes an IDictionary and an existing instance of the bound class.  It reflects on the bound class and sets the values as indicated in the dictionary you pass in.  This method is actually called after the Updating event, but before the Updated event, after ObjectContainerDataSourceView calls Activator.CreateInstance to create an instance of the class you've bound to the form.  The only difference is, we're going to call it here.  &lt;br /&gt;&lt;br /&gt;So what I chose to do is narrow the dictionary down to only those values that have changed, by comparing the OldValues with the NewValues, and then pass the resulting dictionary to the BuildInstance method along with the Person, which, believe it or not, I can get by casting the sender to ObjectContainerDataSourceView, and pulling it out of the Items collection.  My final method looks like this:&lt;br /&gt;&lt;br /&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; UpdatingPerson(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, ObjectContainerDataSourceUpdatingEventArgs e)&lt;br /&gt;{&lt;br /&gt;    &lt;br /&gt;    var source = sender &lt;span class="kwrd"&gt;as&lt;/span&gt; ObjectContainerDataSourceView;&lt;br /&gt;    var person = source.Items[0] &lt;span class="kwrd"&gt;as&lt;/span&gt; Person;&lt;br /&gt;&lt;br /&gt;    Dictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; changedValues = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;();&lt;br /&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (&lt;span class="kwrd"&gt;string&lt;/span&gt; key &lt;span class="kwrd"&gt;in&lt;/span&gt; e.Keys)&lt;br /&gt;    {&lt;br /&gt;        &lt;span class="kwrd"&gt;if&lt;/span&gt; (!e.OldValues[key].Equals(e.NewValues[key]))&lt;br /&gt;            changedValues.Add(key, e.NewValues[key] &lt;span class="kwrd"&gt;as&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    TypeDescriptionHelper.BuildInstance(changedValues, person);&lt;br /&gt;&lt;br /&gt;    _presenter.SavePerson(person);&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This UpdatingPerson method is the handler for the ObjectContainerDataSource's Updating event, and I don't handle the Updated event at all.  &lt;br /&gt;&lt;br /&gt;Another advantage to this method is the fact that I'm not setting anything that hasn't changed.  I leave all the other properties alone.  As they should be.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/996059265581647286-873517937874027487?l=blog.codinglight.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingLight/~4/VE0H2iJLVyk" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.codinglight.com/feeds/873517937874027487/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=996059265581647286&amp;postID=873517937874027487&amp;isPopup=true" title="3 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/873517937874027487?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/873517937874027487?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CodingLight/~3/VE0H2iJLVyk/on-evils-of-objectcontainerdatasource.html" title="On the Evils of ObjectContainerDataSource with MVP Pattern" /><author><name>David Morton</name><uri>http://www.blogger.com/profile/04619192201221893142</uri><email>dvd.morton@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="05004467602404035574" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">3</thr:total><feedburner:origLink>http://blog.codinglight.com/2009/08/on-evils-of-objectcontainerdatasource.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUMMSX04fSp7ImA9WxNSFEU.&quot;"><id>tag:blogger.com,1999:blog-996059265581647286.post-1539699143505027367</id><published>2009-08-28T13:08:00.002-05:00</published><updated>2009-08-28T13:18:08.335-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-08-28T13:18:08.335-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Serialization" /><category scheme="http://www.blogger.com/atom/ns#" term="DataContract" /><category scheme="http://www.blogger.com/atom/ns#" term="binaryformatter" /><title>BinaryFormatter: Fields, Properties or Both?</title><content type="html">I ran into the second person today who was confused on this concept, so I thought I'd post the answer here.  For those of you who missed the question it is: "When I serialize an object, does it only serialize properties, or does it serialize the fields also?". &lt;br /&gt;&lt;br /&gt;Well, the answer depends on &lt;em&gt;how&lt;/em&gt; you serialize the object.  For this post, I'm only going to talk about the BinaryFormatter.  XmlSerializer and DataContractSerializer both work differently, reflecting on properties (for XmlSerializer) or properties and fields (for DataContractSerializer).  Properties serialized with either the XmlSerializer or the DataContractSerializer will actually call any logic within the properties they're setting.  Binary formatter does not.  Here's some example code to prove that BinaryFormatter will leave your properties alone:&lt;br /&gt;&lt;br /&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.IO;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Runtime.Serialization.Formatters.Binary;&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; ConsoleApplication31&lt;br /&gt;{&lt;br /&gt;    &lt;span class="kwrd"&gt;internal&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Program&lt;br /&gt;    {&lt;br /&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main()&lt;br /&gt;        {&lt;br /&gt;            &lt;span class="rem"&gt;// create an instance of the object&lt;/span&gt;&lt;br /&gt;            var thing = &lt;span class="kwrd"&gt;new&lt;/span&gt; StrangeThing();&lt;br /&gt;            &lt;br /&gt;            &lt;span class="rem"&gt;// set the value.&lt;/span&gt;&lt;br /&gt;            thing.SetValue(5);&lt;br /&gt;            Console.WriteLine(&lt;span class="str"&gt;"Initial value is {0}"&lt;/span&gt;, thing.Value);&lt;br /&gt;&lt;br /&gt;            &lt;span class="rem"&gt;// serialize our object. &lt;/span&gt;&lt;br /&gt;            var formatter = &lt;span class="kwrd"&gt;new&lt;/span&gt; BinaryFormatter();&lt;br /&gt;            var stream = &lt;span class="kwrd"&gt;new&lt;/span&gt; MemoryStream();&lt;br /&gt;            formatter.Serialize(stream, thing);&lt;br /&gt;            stream.Position = 0;&lt;br /&gt;&lt;br /&gt;            &lt;span class="rem"&gt;// Deserialize the object.  If this is calling setters, it should throw.&lt;/span&gt;&lt;br /&gt;            var thing2 = (StrangeThing) formatter.Deserialize(stream);&lt;br /&gt;&lt;br /&gt;            &lt;span class="rem"&gt;// Output the result.&lt;/span&gt;&lt;br /&gt;            Console.WriteLine(&lt;span class="str"&gt;"After deserialization, the value is {0}"&lt;/span&gt;, thing2.Value);&lt;br /&gt;            Console.WriteLine(&lt;span class="str"&gt;"Setter was never called"&lt;/span&gt;);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    [Serializable]&lt;br /&gt;    &lt;span class="kwrd"&gt;internal&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; StrangeThing&lt;br /&gt;    {&lt;br /&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; _value;&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; Value&lt;br /&gt;        {&lt;br /&gt;            get { &lt;span class="kwrd"&gt;return&lt;/span&gt; _value; }&lt;br /&gt;            &lt;span class="rem"&gt;// make the setter throw.&lt;/span&gt;&lt;br /&gt;            set { &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; NotImplementedException(); }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span class="rem"&gt;// another method to allow us to set the value. &lt;/span&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; SetValue(&lt;span class="kwrd"&gt;int&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt;)&lt;br /&gt;        {&lt;br /&gt;            _value = &lt;span class="kwrd"&gt;value&lt;/span&gt;;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The binary formatter establishes the actual "binary" representation of the object.  The assumption with binary formatter is that, if the fields are all serialized, the properties will work as expected, because properties are nothing but fancy methods, basically.  Thus, the BinaryFormatter only serializes fields, and never properties. &lt;br /&gt;&lt;br /&gt;Incidentally, serializing only fields is a great way to make a DataContract in WCF.  Should you desire, against my &lt;a href="http://blog.codinglight.com/2009/06/why-you-should-never-make-your-business.html"&gt;earlier admonitions never to make your business objects data contracts&lt;/a&gt;, at least do yourself a favor and never set your properties as DataMembers, only decorate the fields.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/996059265581647286-1539699143505027367?l=blog.codinglight.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingLight/~4/RtAs0bAHWlU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.codinglight.com/feeds/1539699143505027367/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=996059265581647286&amp;postID=1539699143505027367&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/1539699143505027367?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/1539699143505027367?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CodingLight/~3/RtAs0bAHWlU/binaryformatter-fields-properties-or.html" title="BinaryFormatter: Fields, Properties or Both?" /><author><name>David Morton</name><uri>http://www.blogger.com/profile/04619192201221893142</uri><email>dvd.morton@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="05004467602404035574" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://blog.codinglight.com/2009/08/binaryformatter-fields-properties-or.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Ak4NQXs-eCp7ImA9WxNVEE4.&quot;"><id>tag:blogger.com,1999:blog-996059265581647286.post-3338584190636266630</id><published>2009-08-19T11:04:00.004-05:00</published><updated>2009-10-20T06:43:10.550-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-10-20T06:43:10.550-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="escape character" /><category scheme="http://www.blogger.com/atom/ns#" term="string literal" /><title>Understanding Escape Characters (For Beginners)</title><content type="html">I had a question asked on the forum recently about escape characters, and since this is a rather frequent question for C# beginners, I've chosen to reproduce the material here.  If you already understand escape characters in string literals, you can stop reading now. &lt;br /&gt;&lt;br /&gt;Let's say that I have to write a computer program that reads a string character by character.  I've decided that I need to use double quotes to signify the beginning and the end of a string.  Knowing this, I can represent the string&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;bob&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;in my code file by typing:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;"bob"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Great, no problem.  But, what if I want to signify the following:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Bob says, "Hello."&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now I have a problem.  The text I want to represent contains a quote character.  So doing this won't work:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;"Bob says, "Hello""&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Because, the quote signifies the beginning and the ending of ths string. So what do I do?  I use a special character that means "the next character should be considered part of the string, and not signify the beginning or the end of the string.  I'll make that character be a "\". So now, I can type the following to represent my desired string:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;"Bob says, \"Hello\""&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Preceding the quote symbol with a backslash means that the next character is going to be a quote that is considered part of the string, not the end of the string.  Not preceding it means that I'm signifying the end or beginning of the string. &lt;br /&gt;&lt;br /&gt;Now that I've done that, I have another problem.  What if I want to represent the escape character (the "\" character)?  For example, what if I have a string like the following:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;C:\Program Files\Morton\&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Because I've redefined my backslash to mean that the next character is to be taken literally and not as a bounds to the value I'm trying to represent, how do I represent the "\" character itself?  &lt;br /&gt;&lt;br /&gt;To do this, I follow that backslash with another backslash to represent the end of the string.  So now, to represent the string, I do this:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;"C:\\Program Files\\Morton\\"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The above format is what the C# debugger will show when you hover over a particular string variable containing the text:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;C:\Program Files\Morton\&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In other words, it shows the value as it would need to be written in the source file, and not as it actually is.  &lt;br /&gt;&lt;br /&gt;So what about when you need to represent the following text:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;When two backslashes (\\) are together, it means we want to represent a single "\" character.&lt;/span&gt; &lt;br /&gt;&lt;br /&gt;How would you format that in the source code?  Like this:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;"When two backslashes (\\\\) are together, it means we want to represent a single \"\\\" character."&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Confusing, I know, but the idea is still the same.  My actual text I want to represent contains two backslashes in succession, so to represent that, I'd have to put four backslashes in succession.  Also, note how the characters following "single" and before "character" are represented, by using a backslash, quote, backslash, backslash, backslash, quote respectively. &lt;br /&gt;&lt;br /&gt;This is what it means to escape a string.  Though string appear escaped in the debugger, this does not add to their length.   The runtime still recognizes an escaped character as simply one character and not two.  In other words, it does not take into account the escape character (\) when calculating the length of the escaped character (\\). &lt;br /&gt;&lt;br /&gt;This is how C# regular literals are represented.  This is needed in order to ensure that the compiler, which reads a string line by line, can understand the programmers intention, that they intend to enter a literal quote character versus simply ending the string.  I hope this helps to understand the concept.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/996059265581647286-3338584190636266630?l=blog.codinglight.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingLight/~4/AVzwFI4RGrc" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.codinglight.com/feeds/3338584190636266630/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=996059265581647286&amp;postID=3338584190636266630&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/3338584190636266630?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/3338584190636266630?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CodingLight/~3/AVzwFI4RGrc/understanding-escape-characters-for.html" title="Understanding Escape Characters (For Beginners)" /><author><name>David Morton</name><uri>http://www.blogger.com/profile/04619192201221893142</uri><email>dvd.morton@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="05004467602404035574" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://blog.codinglight.com/2009/08/understanding-escape-characters-for.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkUGQXg6cCp7ImA9WxNTEEw.&quot;"><id>tag:blogger.com,1999:blog-996059265581647286.post-3956481969662068274</id><published>2009-08-11T12:41:00.005-05:00</published><updated>2009-08-11T13:10:20.618-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-08-11T13:10:20.618-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="F#" /><title>Houston F# Users Group - August 27th 7:00 PM</title><content type="html">The Houston F# Users Group for August will be taking place August 27th at 7:00 PM in the Catapult Systems Training Room.  We'll be having an interactive, hands-on session where we'll actually get to code some F#.  All levels of knowledge are welcome, and there will be food!&lt;br /&gt;&lt;br /&gt;&lt;a href="http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=10370+Richmond+Avenue+Suite+1250+Houston,+TX+77042&amp;sll=29.694998,-95.416522&amp;sspn=0.014819,0.023882&amp;ie=UTF8&amp;ll=29.728351,-95.55593&amp;spn=0.001852,0.002985&amp;t=h&amp;z=19"&gt;Catapult Systems Houston&lt;/a&gt;&lt;br /&gt;10370 Richmond Avenue&lt;br /&gt;Suite 1250&lt;br /&gt;Houston, TX 77042&lt;br /&gt;&lt;br /&gt;&lt;iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&amp;amp;source=s_q&amp;amp;hl=en&amp;amp;geocode=&amp;amp;q=10370+Richmond+Avenue+Suite+1250+Houston,+TX+77042&amp;amp;sll=29.694998,-95.416522&amp;amp;sspn=0.014819,0.023882&amp;amp;ie=UTF8&amp;amp;t=h&amp;amp;ll=29.728402,-95.555981&amp;amp;spn=0.00163,0.00228&amp;amp;z=18&amp;amp;output=embed"&gt;&lt;/iframe&gt;&lt;br /&gt;&lt;small&gt;&lt;a href="http://maps.google.com/maps?f=q&amp;amp;source=embed&amp;amp;hl=en&amp;amp;geocode=&amp;amp;q=10370+Richmond+Avenue+Suite+1250+Houston,+TX+77042&amp;amp;sll=29.694998,-95.416522&amp;amp;sspn=0.014819,0.023882&amp;amp;ie=UTF8&amp;amp;t=h&amp;amp;ll=29.728402,-95.555981&amp;amp;spn=0.00163,0.00228&amp;amp;z=18" style="color:#0000FF;text-align:left"&gt;View Larger Map&lt;/a&gt;&lt;/small&gt;&lt;br /&gt;&lt;br /&gt;We're the building on the left lower corner of the map (the southwest most building on the north east corner of Richmond and Beltway 8) on the 12th floor.&lt;br /&gt;&lt;br /&gt;See you then!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/996059265581647286-3956481969662068274?l=blog.codinglight.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingLight/~4/1dxPacq80qI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.codinglight.com/feeds/3956481969662068274/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=996059265581647286&amp;postID=3956481969662068274&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/3956481969662068274?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/3956481969662068274?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CodingLight/~3/1dxPacq80qI/houston-f-users-group-august-27th-700.html" title="Houston F# Users Group - August 27th 7:00 PM" /><author><name>David Morton</name><uri>http://www.blogger.com/profile/04619192201221893142</uri><email>dvd.morton@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="05004467602404035574" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://blog.codinglight.com/2009/08/houston-f-users-group-august-27th-700.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0cBRHgzeCp7ImA9WxJaE0Q.&quot;"><id>tag:blogger.com,1999:blog-996059265581647286.post-7875535833092811150</id><published>2009-08-04T05:51:00.008-05:00</published><updated>2009-08-04T09:10:55.680-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-08-04T09:10:55.680-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="quality" /><category scheme="http://www.blogger.com/atom/ns#" term="clean code" /><category scheme="http://www.blogger.com/atom/ns#" term="refactoring" /><title>What is Code Quality Anyways?</title><content type="html">Since I was young, my father has encouraged me to become a writer, so a few years ago, I entertained the idea, and bought a book by Stephen King called "On Writing".  From it, I learned several aspects of good writing.  One of the most memorable was to avoid adverbs ending in -ly.  The reason they should be avoided is because your verbs, nouns and adjectives should describe your intentions without the use of adverbs.  Adverbs are extra fluff, and when overused, are the mark of an immature writing style.  &lt;br /&gt;&lt;br /&gt;Until I read that book, I never thought about the importance of one sentence.  A good novel writer ensures that his audience is not subjected to needless modifiers that serve to support poorly written sentences.  Not only this, but he does it on a consistent basis, one sentence at a time, until the entire novel is written, all the while focusing on the overall plot of the book.  The mark of quality in a novel is it's ability to move the plot forward while avoiding unnecessary distractions.  This hallmark is established with each and every sentence. &lt;br /&gt;&lt;br /&gt;In the publishing world, there are checks and balances to ensure that before a novel is released, the quality of the novel matches up to certain standards.  After the novelist writes the novel, he sends the manuscript to the publisher, who typically suggests one or many edits that the manuscript needs before it's ready to be published.  The novelist then edits his manuscript and repeats this process until the book is ready to publish. &lt;br /&gt;&lt;br /&gt;Now, liken yourself to a novelist.  You have a novel (your code) full of sentences (lines) that you're tasked to write.  The assumption is that you will not only focus on the purpose of the application, but will also focus on how that purpose is to be achieved, by paying attention to each and every line of code.  I've heard it said recently that "it only takes one line to create a dependency".  This statement shows the power that one line of code can have.  It can make or break your application.&lt;br /&gt;&lt;br /&gt;So what is code quality?  Quality code can only come from paying attention to each line you write.  As I'm writing this blog, I'm paying attention to each and every sentence I write.  I'm reviewing each one to verify they communicate my point clearly and concisely.  The reason I'm doing this is because I know there are people who will read this post.  They'll analyze what I'm saying, and won't want to waste their time while reading it.  They expect to learn something from every sentence. &lt;br /&gt;&lt;br /&gt;So why don't we do this as much in our code?  I think it's because we believe that our code will never be read.  It will only be used.  This is a false assumption that needs rejecting.  Every day I read the code I've read in order to modify it, or in order to hunt down a bug.  The way the code is written is almost as important as what it does.  Poorly written code takes longer to maintain.  Well written code can be maintained almost effortlessly. &lt;br /&gt;&lt;br /&gt;Each line of code should serve a purpose.  Each set of lines should be reviewed as it's being written, to ensure the most clear and concise expression of the concept is found.  Each architectural construct should be reviewed for it's flexibility and it's contribution to the overall goal.  This should happen not in a designated refactoring &lt;span style="font-style:italic;"&gt;session&lt;/span&gt;, but during the moment-by-moment process of coding.&lt;br /&gt;&lt;br /&gt;This takes patience, consistency and the ability to clearly adhere to and express the purpose.  &lt;br /&gt;&lt;br /&gt;Code quality, in my definition, is a well-assembled collection of well-expressed lines of code, none of them being taken for granted.  This is a basic concept, but one that needs reinforcing from time to time.  There are so many concepts to quality programming that it takes a lifetime to master them all (if indeed they can be mastered), but for a good start allow me to suggest &lt;a href="http://wiki.codinglight.com/SOLID.ashx"&gt;SOLID principles&lt;/a&gt; and &lt;a href="http://wiki.codinglight.com/DesignPatterns.ashx"&gt;design patterns&lt;/a&gt;.  Professional programmers will learn these techniques and use them to their advantage.  Poor programmers will abuse the code and muddle it's intentions.  &lt;br /&gt;&lt;br /&gt;Refactor in the small, and refactor consistently as you go.  A good place to start might be to begin reading Sean Chambers' current blog series entitled &lt;a href="http://www.lostechies.com/blogs/sean_chambers/archive/2009/07/31/31-days-of-refactoring.aspx" target="_blank"&gt;31 Days of Refactoring&lt;/a&gt;.  &lt;br /&gt;&lt;br /&gt;Learn these techniques and apply them as you go, not after the fact, and you'll find at the end that your code can be as enjoyable to read as some of the world's greatest authors, from Hemingway to King to Rowling.&lt;br /&gt;&lt;br /&gt;Write code like it's going to be read.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/996059265581647286-7875535833092811150?l=blog.codinglight.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingLight/~4/enDWFBINoqg" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.codinglight.com/feeds/7875535833092811150/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=996059265581647286&amp;postID=7875535833092811150&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/7875535833092811150?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/7875535833092811150?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CodingLight/~3/enDWFBINoqg/what-is-code-quality-anyways.html" title="What is Code Quality Anyways?" /><author><name>David Morton</name><uri>http://www.blogger.com/profile/04619192201221893142</uri><email>dvd.morton@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="05004467602404035574" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://blog.codinglight.com/2009/08/what-is-code-quality-anyways.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D08FRX89fip7ImA9WxJaE00.&quot;"><id>tag:blogger.com,1999:blog-996059265581647286.post-7239415168463348662</id><published>2009-08-03T08:07:00.005-05:00</published><updated>2009-08-03T08:23:34.166-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-08-03T08:23:34.166-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Wiki" /><category scheme="http://www.blogger.com/atom/ns#" term="off-topic" /><title>The Wiki is Live</title><content type="html">I've finally done it.  For a while now I've been looking for a way to organize my thoughts efficiently and effectively, while &lt;span style="font-style:italic;"&gt;actually retaining&lt;/span&gt; the things I'm learning.  The wiki is designed to help with that, and I've been working on it for a couple of weeks now.  &lt;br /&gt;&lt;br /&gt;Generally I get my information from one of a few sources (in no particular order):&lt;br /&gt;&lt;br /&gt;1. Daily life. I learn quite a bit just by programming. &lt;br /&gt;2. Podcasts. &lt;br /&gt;3. Online Forums (most notably the MSDN forums, where I contribute heavily)&lt;br /&gt;4. Blogs I subscribe to. &lt;br /&gt;5. Blog posts people send to me. &lt;br /&gt;6. Talking with people older and more experienced than myself. &lt;br /&gt;&lt;br /&gt;Sometimes, I find that while researching this information, there's bits and pieces of information I need in order to fully understand the information I'm looking at, so I'm making a commitment to actually follow these breadcrumb trails to better learn at least a little of the concepts and/or technologies that seem integral to the conversation at hand. &lt;br /&gt;&lt;br /&gt;But this presents a problem.  What pieces of information am I going to record?  Certainly I don't have the time or patience to seek out a &lt;span style="font-style:italic;"&gt;full&lt;/span&gt; understanding of &lt;span style="font-style:italic;"&gt;everything&lt;/span&gt;, so I have to limit what information I seek out to the minimum, earmarking things I want to revisit, and remembering the chief point of the rabbit trail that led me to learn that bit of information I'm learning, so I can ultimately accomplish my goal. &lt;br /&gt;&lt;br /&gt;The problem is this: I'll have several pieces of information unfinished. &lt;br /&gt;&lt;br /&gt;The good news is this: That's the life of the developer, so I'm not alone. &lt;br /&gt;&lt;br /&gt;We will &lt;span style="font-style:italic;"&gt;never&lt;/span&gt; know everything about everything, so the best we can do is learn alot about a little, and the rest we might know a little about.  I believe the Wiki expresses this sentiment.  There are some things that I know little about, and don't need to know about in depth, so I don't go in depth.  In fact, some of the wiki entries are single sentence entries, simply meant as stubs to be fleshed out at a later date, or in some cases, never.  Nevertheless, I feel it's extremely important to document my journey, in an effort to help those who might come after me to learn from me some of the things I've learned.  &lt;br /&gt;&lt;br /&gt;So, after much introduction, allow me to introduce: &lt;a href="http://wiki.codinglight.com/"&gt;Coding Light Wiki&lt;/a&gt;.  Enjoy.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/996059265581647286-7239415168463348662?l=blog.codinglight.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingLight/~4/9-uGSjpaChQ" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.codinglight.com/feeds/7239415168463348662/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=996059265581647286&amp;postID=7239415168463348662&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/7239415168463348662?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/7239415168463348662?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CodingLight/~3/9-uGSjpaChQ/wiki-is-live.html" title="The Wiki is Live" /><author><name>David Morton</name><uri>http://www.blogger.com/profile/04619192201221893142</uri><email>dvd.morton@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="05004467602404035574" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://blog.codinglight.com/2009/08/wiki-is-live.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0EBQXk-fCp7ImA9WxJaEkk.&quot;"><id>tag:blogger.com,1999:blog-996059265581647286.post-623336529324722703</id><published>2009-08-01T12:32:00.006-05:00</published><updated>2009-08-02T15:40:50.754-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-08-02T15:40:50.754-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="simplicity" /><category scheme="http://www.blogger.com/atom/ns#" term="rebranding" /><category scheme="http://www.blogger.com/atom/ns#" term="Coding Light" /><category scheme="http://www.blogger.com/atom/ns#" term="off-topic" /><title>New Name and Style (and Some Comments on Simplicity)</title><content type="html">So I decided to shake things up a little bit... I've had this blog for over a year now, and this morning decided to edit the page... "a little".  Well, that got blown to bits when I clicked "Save Template" on Blogger, thinking it would allow me to download and save my current template.  "Save Template" actually means "apply the current template".  Suddenly my whole blog's color scheme had changed, and I lost all my adjustments.  &lt;br /&gt;&lt;br /&gt;I also realized my label cloud was completely broken.  That hurt me. &lt;br /&gt;&lt;br /&gt;So began the metamorphosis.  I started editing the templates and finally found a template I liked, and decided in the process to rename my blog to something a little more creative and descriptive than the previous name: &lt;u&gt;David Morton&lt;/u&gt;.&lt;br /&gt;&lt;br /&gt;I decided on &lt;u&gt;Coding Light&lt;/u&gt;.  The idea being that code &lt;span style="font-style:italic;"&gt;should&lt;/span&gt; be light.  There are so many "cool" things out there right now in shiny silver boxes, that it's easy to get stuck in the trap of thinking that the right combination of tools can effectively eliminate the difficulty and complexity in programming.  Many tools exist for the sole purpose of flexibility.  Bob Martin has astutely &lt;a href="http://www.artima.com/intv/flexplex2.html"&gt;observed&lt;/a&gt;:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;The cost of flexibility is complexity. Every time you put extra stuff into your code to make it more flexible, you are usually adding more complexity. If your guess about the flexibility needs of your software is correct, then you are ahead of the game. You've gained. But if you get it wrong, you've only added complexity that makes it more difficult to change your software. You're obviously not getting the payback.&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;What does this mean?  This means we should stop making such an attempt to create the most flexible, catch-all algorithms and frameworks possible, and instead begin focusing on the problem domain.  Instead of trying to discover the wheel, start addressing the problem you're paid to solve, and do it simply, directly and without unneeded abstractions (see: &lt;a href="http://en.wikipedia.org/wiki/You_Ain't_Gonna_Need_It"&gt;YAGNI&lt;/a&gt;).  This is what it means to "code light".  Keep the weight of your architecture and your algorithms light.  Don't over abstract.  &lt;a href="http://en.wikipedia.org/wiki/Keep_it_simple_stupid"&gt;KISS&lt;/a&gt;. &lt;br /&gt;&lt;br /&gt;Now, don't get me wrong... I love the new stuff as much as the next guy, but the new stuff has it's place.  Our primary goal when learning a new framework or a new technology is not to look for places to use it, but to instead figure out where it &lt;span style="font-style:italic;"&gt;should&lt;/span&gt; be used, while continuing to default to the simplest solution possible.  Sometimes the simplest solution is the new language or framework, and sometimes it's not.  It's the role of the adventurous geek to learn how to discern the difference. &lt;br /&gt;&lt;br /&gt;That being said, welcome to the "re-branded" blog.  I have no plans to stop blogging on some of the algorithms and tricks I've discovered or seen other people use, but I do have plans to start increasing posts about coding standards, simplicity, and other language-agnostic thoughts.  &lt;br /&gt;&lt;br /&gt;Glad you could drop by.&lt;br /&gt;&lt;br /&gt;EDIT: Based on a comment by &lt;a href="http://flux88.com/"&gt;Ben Scheirman&lt;/a&gt;, I've decided, despite my love for the label cloud, to remove it completely, as an action to be taken to demonstrate my new commitment to simplicity, not only in coding, but in the design of the site itself.  Turns out nobody really used it anyways, so it was just cluttering things up.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/996059265581647286-623336529324722703?l=blog.codinglight.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingLight/~4/gTNi3dYVfjo" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.codinglight.com/feeds/623336529324722703/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=996059265581647286&amp;postID=623336529324722703&amp;isPopup=true" title="3 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/623336529324722703?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/623336529324722703?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CodingLight/~3/gTNi3dYVfjo/new-name-and-style.html" title="New Name and Style (and Some Comments on Simplicity)" /><author><name>David Morton</name><uri>http://www.blogger.com/profile/04619192201221893142</uri><email>dvd.morton@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="05004467602404035574" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">3</thr:total><feedburner:origLink>http://blog.codinglight.com/2009/08/new-name-and-style.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkABQXc4cCp7ImA9WxJbGEQ.&quot;"><id>tag:blogger.com,1999:blog-996059265581647286.post-2801264573164158339</id><published>2009-07-29T15:14:00.003-05:00</published><updated>2009-07-29T15:19:10.938-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-07-29T15:19:10.938-05:00</app:edited><title>Assembly Resolution with AppDomain.AssemblyResolve</title><content type="html">Plugin frameworks often rely on runtime assembly resolution, and sometimes the assemblies to be resolved don't lie within the directory structure of the executable, nor are they located in the GAC.  In these cases, you can use the &lt;a href="http://msdn.microsoft.com/en-us/library/system.appdomain.assemblyresolve.aspx"&gt;AppDomain.AssemblyResolve&lt;/a&gt; event to resolve assemblies at runtime. The key with the AssemblyResolve method is that it must be put into place before attempting to instantiate any of the classes where an assembly needs to be loaded. Sample code exists on the MSDN Documentation for System.Assembly.AssemblyResolve. &lt;br /&gt;&lt;br /&gt;Before implementing runtime assembly resolution, it's important to understand how methods are loaded at runtime. &lt;br /&gt;&lt;br /&gt;When a method is first called, that method is JITted, or "Just-In-Time Compiled". Essentially, all the IL code for that method is loaded and then compiled into CPU instructions. Any types that are used within that method are also resolved when the method is JIT compiled, in order to ensure that the entire method is "safe" for execution. Essentially, what this means to Assembly Resolution using the AppDomain.AssemblyResolve event is that the attachment to the event handler cannot reside within the same method that calls the type that will have to be resolved using the event handler. The reason for this is simple... the event handler must be attached before the type is resolved. If the event handler is attached within the same method, then the JIT compiler will attempt to resolve the type before executing the first instruction in the method, including the instruction to attach the event handler to the AssemblyResolve event, causing the whole application to fail. &lt;br /&gt;&lt;br /&gt;Thus, a good example of attaching an assembly at runtime would be the following. The Widget class is the class to load, and it does not reside within the same directory as the executable. Instead, it resides in a directory that is only identified with a relative path. This relative path can be searched at runtime to find the specific assembly that is needed to load. &lt;br /&gt;&lt;br /&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.IO;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Reflection;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; ClassLibrary1;&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; ConsoleApplication6&lt;br /&gt;{&lt;br /&gt;    &lt;span class="kwrd"&gt;internal&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Program&lt;br /&gt;    {&lt;br /&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; ResolutionPath = @"..\..\..\ClassLibrary1\bin\debug\";&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main()&lt;br /&gt;        {&lt;br /&gt;            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomainAssemblyResolve;&lt;br /&gt;            RunWidget();&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; RunWidget()&lt;br /&gt;        {&lt;br /&gt;            var widget = &lt;span class="kwrd"&gt;new&lt;/span&gt; WidgetInOtherAssembly();&lt;br /&gt;            Console.WriteLine(widget);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; Assembly CurrentDomainAssemblyResolve(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, ResolveEventArgs args)&lt;br /&gt;        {&lt;br /&gt;            Assembly[] currentAssemblies = AppDomain.CurrentDomain.GetAssemblies();&lt;br /&gt;&lt;br /&gt;            &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; i = 0; i &amp;lt; currentAssemblies.Length; i++)&lt;br /&gt;            {&lt;br /&gt;                &lt;span class="kwrd"&gt;if&lt;/span&gt; (currentAssembliesi.FullName == args.Name)&lt;br /&gt;                {&lt;br /&gt;                    &lt;span class="kwrd"&gt;return&lt;/span&gt; currentAssembliesi;&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; FindAssembliesInDirectory(args.Name, ResolutionPath);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; Assembly FindAssembliesInDirectory(&lt;span class="kwrd"&gt;string&lt;/span&gt; assemblyName, &lt;span class="kwrd"&gt;string&lt;/span&gt; directory)&lt;br /&gt;        {&lt;br /&gt;            &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (&lt;span class="kwrd"&gt;string&lt;/span&gt; file &lt;span class="kwrd"&gt;in&lt;/span&gt; Directory.GetFiles(directory))&lt;br /&gt;            {&lt;br /&gt;                Assembly assm;&lt;br /&gt;&lt;br /&gt;                &lt;span class="kwrd"&gt;if&lt;/span&gt; (TryLoadAssemblyFromFile(file, assemblyName, &lt;span class="kwrd"&gt;out&lt;/span&gt; assm))&lt;br /&gt;                    &lt;span class="kwrd"&gt;return&lt;/span&gt; assm;&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;null&lt;/span&gt;;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; TryLoadAssemblyFromFile(&lt;span class="kwrd"&gt;string&lt;/span&gt; file, &lt;span class="kwrd"&gt;string&lt;/span&gt; assemblyName, &lt;span class="kwrd"&gt;out&lt;/span&gt; Assembly assm)&lt;br /&gt;        {&lt;br /&gt;            &lt;span class="kwrd"&gt;try&lt;/span&gt;&lt;br /&gt;            {&lt;br /&gt;                &lt;span class="rem"&gt;// Convert the filename into an absolute file name for &lt;/span&gt;&lt;br /&gt;                &lt;span class="rem"&gt;// use with LoadFile. &lt;/span&gt;&lt;br /&gt;                file = &lt;span class="kwrd"&gt;new&lt;/span&gt; FileInfo(file).FullName;&lt;br /&gt;&lt;br /&gt;                &lt;span class="kwrd"&gt;if&lt;/span&gt; (AssemblyName.GetAssemblyName(file).FullName == assemblyName)&lt;br /&gt;                {&lt;br /&gt;                    assm = Assembly.LoadFile(file);&lt;br /&gt;                    &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;true&lt;/span&gt;;&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;            &lt;span class="kwrd"&gt;catch&lt;/span&gt;&lt;br /&gt;            {&lt;br /&gt;                &lt;span class="rem"&gt;/* Do Nothing */&lt;/span&gt;&lt;br /&gt;            }&lt;br /&gt;            assm = &lt;span class="kwrd"&gt;null&lt;/span&gt;;&lt;br /&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;false&lt;/span&gt;;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;} &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Changes To ResolveEventArgs in .NET 4.0&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In .NET 4.0, the ResolveEventArgs class has a new property called "RequestingAssembly", which returns the name of the assembly requesting resolution. This has been done in order to enable the ability to execute specific code based on which assembly was requesting the resolution. &lt;br /&gt;&lt;br /&gt;You can see more information on these changes &lt;a href="http://blogs.msdn.com/clrteam/archive/2009/07/15/clr-4-making-the-assemblyresolve-event-more-useful.aspx"&gt;here&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/996059265581647286-2801264573164158339?l=blog.codinglight.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingLight/~4/BcDmt60cWnA" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.codinglight.com/feeds/2801264573164158339/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=996059265581647286&amp;postID=2801264573164158339&amp;isPopup=true" title="4 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/2801264573164158339?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/2801264573164158339?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CodingLight/~3/BcDmt60cWnA/assembly-resolution-with.html" title="Assembly Resolution with AppDomain.AssemblyResolve" /><author><name>David Morton</name><uri>http://www.blogger.com/profile/04619192201221893142</uri><email>dvd.morton@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="05004467602404035574" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">4</thr:total><feedburner:origLink>http://blog.codinglight.com/2009/07/assembly-resolution-with.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DE8FR349eSp7ImA9WxJbGE0.&quot;"><id>tag:blogger.com,1999:blog-996059265581647286.post-9211493750668181589</id><published>2009-07-28T13:38:00.004-05:00</published><updated>2009-07-28T13:46:56.061-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-07-28T13:46:56.061-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="beginner" /><title>On Method Overloading Best Practices</title><content type="html">C# allows method overloading. An overload is defined as a method that has the same name as another method, and differs only in the number and/or type of parameters it receives. (Technically, .NET allows creation of overloads based only on the return type but this construct is not allowed in C#).&lt;br /&gt;&lt;br /&gt;The .NET Framework uses method overloading with several of it's methods. For example, the Activator.CreateInstance method has no fewer than 14 distinct overloads for it's usage. Each of these overloads provides the developer flexibility with how he/she chooses to call this method, and can greatly abstract out some of the more menial tasks that may have to be done by the developer, such as casting from one type to another before making a call, or having to research default parameters for a method in order to ensure the proper parameters are passed into the method.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;When to Use Method Overloading&lt;/span&gt;&lt;/b&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:6;"&gt;&lt;span class="Apple-style-span"  style="font-size:24px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;Method overloading should be used to allow your callers greater type and parameter options when calling a specific method. Good uses of method overloading are as follows:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;Default values&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;When a method has parameters for which "acceptable defaults" can be defined, an overload of that method that omits the defaulted parameter can be created which would subsequently call the method that contains the parameter for which there is a default, passing in the default value. An example of this might be the Int32.TryParse method, which has two overloads:&lt;br /&gt;&lt;br /&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;bool&lt;/span&gt; TryParse(&lt;span class="kwrd"&gt;string&lt;/span&gt; s, &lt;span class="kwrd"&gt;out&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; result);&lt;br /&gt;&lt;span class="kwrd"&gt;bool&lt;/span&gt; TryParse(&lt;span class="kwrd"&gt;string&lt;/span&gt; s, NumberStyles style, IFormatProvider provider, &lt;span class="kwrd"&gt;out&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; result);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Both of these methods ultimately route to the same method, namely the internal static method Number.TryParseInt32. The difference is that the first one passes NumberStyles.Integer and NumberFormatInfo.CurrentInfo as the default values for style and provider, whereas the second overload passes the user defined values. Therefore, the first one is provided for convenience for default values.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;Type conversion convenience&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;If a piece of data can be represented using multiple types, then overloads can be created to abstract type conversions away from the client. An example might be a fictional "CreateInstance" method.&lt;br /&gt;&lt;br /&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;T CreateInstance();&lt;br /&gt;&lt;span class="kwrd"&gt;object&lt;/span&gt; CreateInstance(Type type);&lt;br /&gt;&lt;span class="kwrd"&gt;object&lt;/span&gt; CreateInstance(&lt;span class="kwrd"&gt;string&lt;/span&gt; typeName);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;These three methods all accomplish the same purpose, namely, creating an instance from a representation of a type. Two of them are overloads. In the first method, the representation is passed via a generic type parameter, T. The next method passes the type via an instance of the Type class, and the third method (which is an overload of the second method) passes the type via it's full name. It's important to note that these three parameter types are intrinsically the same piece of data only represented in different ways. They all three represent a single type, which is then used to create an instance. If I wanted to then create an instance of a class based on another piece of data other than the type, I should not create an overload, but should create a new method with a new method name.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;When Not to Use Overloading&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;There are a couple of instances where method overloads would not be appropriate.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;To clean up Intellisense&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Designing anything within an object model simply to cater to ease of use when it comes to a specific technology is almost always a mistake. Cleaning up Intellisense is not related to having a clear code base, and catering to Intellisense in this situation can muddle the true purpose of your methods.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;To take advantage of the type differences of intrinsically different pieces of data&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;An example of this could be overloads like the following:&lt;br /&gt;&lt;br /&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;Product GetProduct(Guid id);&lt;br /&gt;Product GetProduct(&lt;span class="kwrd"&gt;string&lt;/span&gt; name);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The first issue here would be that the name of the methods, GetProduct, does not accurately or completely describe the actions that the method would take in order to accomplish it's goal. In both situations, a Product instance is retrieved, but both situations accomplish this task based on intrinsically different data. An id is not a name, and cannot be converted to a name without having more information. Creating this kind of overload makes compiler resolutions dependent upon whatever type the data happens to be at the moment.&lt;br /&gt;&lt;br /&gt;Also, potential inconsistencies in naming can occur in the situation where a third overload is to be added. Suppose there is a client reference number for each product, and a third overload needs to be created to manage fetching products by this number. Suppose, furthermore, that the client reference number is of the type string. The preferred overload would look like this:&lt;br /&gt;&lt;br /&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;Product GetProduct(&lt;span class="kwrd"&gt;string&lt;/span&gt; clientRef);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Unfortunately, since overloads are only distinguished based on the name and the incoming parameter types, the above method would cause a compiler error when combined with the previous two methods, leaving the developer with only two choices: rename all the methods for consistency, which would also force callers to change their code, or else use a different name for the new method, causing an inconsistency, and learn to deal with it. Of course, either option is no good.&lt;br /&gt;&lt;br /&gt;In the end, the best option is to only use method overloading when the methods to be overloaded accomplish the exact same task given the same data where portions of the data either have acceptable default values, or else are already the same bit of data only represented in different formats. &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/996059265581647286-9211493750668181589?l=blog.codinglight.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingLight/~4/EI-ArAp17NI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.codinglight.com/feeds/9211493750668181589/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=996059265581647286&amp;postID=9211493750668181589&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/9211493750668181589?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/9211493750668181589?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CodingLight/~3/EI-ArAp17NI/on-method-overloading-best-practices.html" title="On Method Overloading Best Practices" /><author><name>David Morton</name><uri>http://www.blogger.com/profile/04619192201221893142</uri><email>dvd.morton@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="05004467602404035574" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://blog.codinglight.com/2009/07/on-method-overloading-best-practices.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEIMSXk9fyp7ImA9WxJbF08.&quot;"><id>tag:blogger.com,1999:blog-996059265581647286.post-2720123740053350333</id><published>2009-07-27T14:19:00.003-05:00</published><updated>2009-07-27T14:23:08.767-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-07-27T14:23:08.767-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="beginner" /><title>Automatically Find the Namespace of a Class and Add a Using Statement in Visual Studio</title><content type="html">This is an all-too-common question on the forums for me not to address it here.  This post concerns a very basic C# concept.   &lt;br /&gt;&lt;br /&gt;Sometimes, when adding a code snippet, it's possible you might get an error that says something to the effect of "The name "xxx" does not exist in the current context". &lt;br /&gt;&lt;br /&gt;At compile time, a namespace reference must be found in order to resolve classes that will be used within an application. Classes can be resolved to their namespaces either with the &lt;a href="http://msdn.microsoft.com/en-us/library/sf0df423.aspx"&gt;using directive&lt;/a&gt;, or by using the fully qualified class name when referring to a class. &lt;br /&gt;&lt;br /&gt;Employing the using directive would look like this:&lt;br /&gt;&lt;br /&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Reflection;&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; MyNamespace&lt;br /&gt;{&lt;br /&gt;   &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Program&lt;br /&gt;   {&lt;br /&gt;      &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main(&lt;span class="kwrd"&gt;string&lt;/span&gt;[] args)&lt;br /&gt;      {&lt;br /&gt;         Console.WriteLine(Assembly.GetExecutingAssembly().GetName().Version);&lt;br /&gt;      }&lt;br /&gt;   }  &lt;br /&gt;} &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;While employing a fully qualified namespace reference would look like this:&lt;br /&gt;&lt;br /&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; MyNamespace&lt;br /&gt;{&lt;br /&gt;   &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Program&lt;br /&gt;   {&lt;br /&gt;      &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main(&lt;span class="kwrd"&gt;string&lt;/span&gt;[] args)&lt;br /&gt;      {&lt;br /&gt;          System.Console.WriteLine(System.Reflection.Assembly.GetExecutingAssembly().GetName().Version);&lt;br /&gt;      }&lt;br /&gt;   }&lt;br /&gt;} &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Typically, the using directive is preferred, as it usually creates cleaner, and easier to read code, but sometimes the fully qualified class name makes more sense, especially when two or more namespaces contain different classes with the same name. &lt;br /&gt;&lt;br /&gt;If both of these above constructs are missing from the code file, the error described above will be the result. &lt;br /&gt;&lt;br /&gt;Most of the time, this situation can be done by following the following simple steps:&lt;br /&gt;&lt;br /&gt;1. Place the text caret in the middle of the class name that is causing the error. Alternatively, you can simply double click on the error in the Errors window.&lt;br /&gt;&lt;br /&gt;2. Press Shift+Alt+F10. If the class can be found, a set of options will appear to add the namespace reference to the class. The options that start with "using" will add the using directive to the top of the code file, while the options that simply have the namespace name will change the class reference in code to use the fully qualified class name. &lt;br /&gt;&lt;br /&gt;Occasionally, however, it's necessary to add a reference to the assembly containing the class. You can do this by right clicking the "References" folder within the project, and selecting "Add Reference....". Select the applicable tab:&lt;br /&gt;&lt;br /&gt;.NET - For .NET Assemblies located in the GAC. &lt;br /&gt;&lt;br /&gt;COM - For older COM assemblies registered in the system.&lt;br /&gt;&lt;br /&gt;Projects - For references to projects that reside within the same solution as the current project. &lt;br /&gt;&lt;br /&gt;Browse - To browse the file system for a specific file. &lt;br /&gt;&lt;br /&gt;Recent - For references that have recently been added. &lt;br /&gt;&lt;br /&gt;Finally, select the assembly you need to reference, and click OK. &lt;br /&gt;&lt;br /&gt;After a reference has been added, you can go back to step 1 above, and ensure the using directive or the fully qualified class name results in the proper resolution of the class.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/996059265581647286-2720123740053350333?l=blog.codinglight.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingLight/~4/3RYJ-InsCzU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.codinglight.com/feeds/2720123740053350333/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=996059265581647286&amp;postID=2720123740053350333&amp;isPopup=true" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/2720123740053350333?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/2720123740053350333?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CodingLight/~3/3RYJ-InsCzU/automatically-find-namespace-of-class.html" title="Automatically Find the Namespace of a Class and Add a Using Statement in Visual Studio" /><author><name>David Morton</name><uri>http://www.blogger.com/profile/04619192201221893142</uri><email>dvd.morton@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="05004467602404035574" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total><feedburner:origLink>http://blog.codinglight.com/2009/07/automatically-find-namespace-of-class.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0YAQns7eSp7ImA9WxJaEUk.&quot;"><id>tag:blogger.com,1999:blog-996059265581647286.post-7498957213645044269</id><published>2009-07-15T09:58:00.004-05:00</published><updated>2009-08-01T10:39:03.501-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-08-01T10:39:03.501-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Environment" /><category scheme="http://www.blogger.com/atom/ns#" term="IOException" /><category scheme="http://www.blogger.com/atom/ns#" term="delete" /><category scheme="http://www.blogger.com/atom/ns#" term="directory" /><category scheme="http://www.blogger.com/atom/ns#" term="CurrentDirectory" /><category scheme="http://www.blogger.com/atom/ns#" term="another process" /><title>IOException While Trying to Delete a Folder?!</title><content type="html">Make sure you don't step on your own toes.  The following code illustrates...&lt;br /&gt;&lt;br /&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.IO;&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;internal&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Program&lt;br /&gt;{&lt;br /&gt;    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main(&lt;span class="kwrd"&gt;string&lt;/span&gt;[] args)&lt;br /&gt;    {&lt;br /&gt;        &lt;span class="kwrd"&gt;string&lt;/span&gt; directory = @"C:\atemporaryfolder\";&lt;br /&gt;        Directory.CreateDirectory(directory);&lt;br /&gt;        Environment.CurrentDirectory = directory;&lt;br /&gt;        Directory.Delete(directory);&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Who's using the folder?  You are.  Whenever Environment.CurrentDirectory is set in an application, it prevents anything else from deleting the folder.  Note that the Environment.CurrentDirectory can also be set through a variety of other means, including the FolderBrowserDialog, OpenFileDialog and SaveFileDialog.  &lt;br /&gt;&lt;br /&gt;What's the solution?  Simple.  Set Environment.CurrentDirectory to something else.  @"C:\" works just fine.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/996059265581647286-7498957213645044269?l=blog.codinglight.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingLight/~4/ClOVIos8_pU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.codinglight.com/feeds/7498957213645044269/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=996059265581647286&amp;postID=7498957213645044269&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/7498957213645044269?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/7498957213645044269?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CodingLight/~3/ClOVIos8_pU/ioexception-while-trying-to-delete.html" title="IOException While Trying to Delete a Folder?!" /><author><name>David Morton</name><uri>http://www.blogger.com/profile/04619192201221893142</uri><email>dvd.morton@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="05004467602404035574" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://blog.codinglight.com/2009/07/ioexception-while-trying-to-delete.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEEDQno4cSp7ImA9WxJUFk0.&quot;"><id>tag:blogger.com,1999:blog-996059265581647286.post-7514719825362688383</id><published>2009-07-14T16:21:00.003-05:00</published><updated>2009-07-14T16:24:33.439-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-07-14T16:24:33.439-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="array" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="syntax" /><title>C# 3.0 Syntax of the Day</title><content type="html">Can't believe I missed this one...&lt;br /&gt;&lt;br /&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;var items = &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;[] { &lt;span class="str"&gt;"David"&lt;/span&gt;, &lt;span class="str"&gt;"Jennifer"&lt;/span&gt; };&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;versus:&lt;br /&gt;&lt;br /&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;var items = &lt;span class="kwrd"&gt;new&lt;/span&gt;[] { &lt;span class="str"&gt;"David"&lt;/span&gt;, &lt;span class="str"&gt;"Jennifer"&lt;/span&gt; };&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Yep, that's right!  "new[]" is okay.  The compiler will infer the type of the array based on the type of the items within the squigglies.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/996059265581647286-7514719825362688383?l=blog.codinglight.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CodingLight/~4/a4mYSOr41JU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.codinglight.com/feeds/7514719825362688383/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=996059265581647286&amp;postID=7514719825362688383&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/7514719825362688383?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/996059265581647286/posts/default/7514719825362688383?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CodingLight/~3/a4mYSOr41JU/c-30-syntax-of-day.html" title="C# 3.0 Syntax of the Day" /><author><name>David Morton</name><uri>http://www.blogger.com/profile/04619192201221893142</uri><email>dvd.morton@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="05004467602404035574" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://blog.codinglight.com/2009/07/c-30-syntax-of-day.html</feedburner:origLink></entry></feed>
