<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>D Melodic Minor Accidental</title><link>http://blogs.msdn.com/theoy/default.aspx</link><description>A conglomeration of random thoughts on C#, .NET, OOP, and working at Microsoft</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Short, sweet, to the point - Framework 2.0 is out!</title><link>http://blogs.msdn.com/theoy/archive/2005/10/30/487100.aspx</link><pubDate>Mon, 31 Oct 2005 02:49:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:487100</guid><dc:creator>TheoY</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/theoy/comments/487100.aspx</comments><wfw:commentRss>http://blogs.msdn.com/theoy/commentrss.aspx?PostID=487100</wfw:commentRss><description>&lt;P&gt;&lt;FONT face=Verdana&gt;&lt;FONT size=2&gt;In case you haven't heard (or even if you have, IMHO this could never be spread too fast), .NET Framework 2.0 is out.&amp;nbsp; This is a major improvement over the 1.1 Framework in terms of stability, and overall offerings including the ever-so-important generics support.&amp;nbsp; You can download the x86 version of the redistributable here: &lt;/FONT&gt;&lt;A href="http://www.microsoft.com/downloads/details.aspx?familyid=0856eacb-4362-4b0d-8edd-aab15c5e04f5"&gt;&lt;FONT size=2&gt;http://www.microsoft.com/downloads/details.aspx?familyid=0856eacb-4362-4b0d-8edd-aab15c5e04f5&lt;/FONT&gt;&lt;/A&gt;&lt;FONT size=2&gt;.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;I personally will be moving to generics and never looking back, so it'd be best to get the newest version of the runtime to as many people as soon as possible :)&lt;BR&gt;&lt;BR&gt;There are also links under the "related links" section of that page to get the redistributable for x64 (AMD64), or IA64 (Itanium), as well as the Framework SDK (free, comes with a couple extra tools for developers).&lt;BR&gt;&lt;BR&gt;Visual Studio 2005 ("Whidbey") has also shipped, and will be hitting the store shelves very soon.&amp;nbsp; Express versions should also be downloadable soon, if not up there already.&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=487100" width="1" height="1"&gt;</description></item><item><title>"Find All References" Design, regarding interface members</title><link>http://blogs.msdn.com/theoy/archive/2005/07/06/436254.aspx</link><pubDate>Thu, 07 Jul 2005 01:42:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:436254</guid><dc:creator>TheoY</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/theoy/comments/436254.aspx</comments><wfw:commentRss>http://blogs.msdn.com/theoy/commentrss.aspx?PostID=436254</wfw:commentRss><description>&lt;P&gt;&lt;FONT face=Verdana&gt;&lt;FONT size=2&gt;One of the things that I've been working on to help finish Whidbey, are the new refactoring features.&amp;nbsp; However, I've recently found myself questioning the design for "Find All References", in regards to its handling of interface members.&amp;nbsp; I discovered this behavior while writing a toy project in C#, but the following example illustrates it better, in my opinion.&amp;nbsp; Imagine you're writing a generalized library - and provide two different interfaces, IResource and IStream.&amp;nbsp; Both of them have the notion of a Close() method (for simplicity sake, I'll put&amp;nbsp;the interfaces&amp;nbsp;in separate files, which will help make it easier to see the design confusion):&lt;/P&gt;
&lt;P&gt;
&lt;TABLE class=MsoTableGrid style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BACKGROUND: white; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.45pt 5.75pt 1.45pt 5.75pt; mso-yfti-tbllook: 480; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext" cellSpacing=0 cellPadding=0 border=1&gt;
&lt;TBODY&gt;
&lt;TR style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"&gt;
&lt;TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.75pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.75pt; PADDING-BOTTOM: 1.45pt; BORDER-LEFT: windowtext 1pt solid; PADDING-TOP: 1.45pt; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt" vAlign=top&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;namespace&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt; Library {&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;interface&lt;/SPAN&gt; &lt;SPAN style="COLOR: teal"&gt;IResource&lt;/SPAN&gt; {&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; Close();&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;}&lt;BR style="mso-special-character: line-break"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;TABLE class=MsoTableGrid style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BACKGROUND: white; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.45pt 5.75pt 1.45pt 5.75pt; mso-yfti-tbllook: 480; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext" cellSpacing=0 cellPadding=0 border=1&gt;
&lt;TBODY&gt;
&lt;TR style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"&gt;
&lt;TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.75pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.75pt; PADDING-BOTTOM: 1.45pt; BORDER-LEFT: windowtext 1pt solid; PADDING-TOP: 1.45pt; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt" vAlign=top&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;namespace&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt; Library {&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;interface&lt;/SPAN&gt; &lt;SPAN style="COLOR: teal"&gt;IStream&lt;/SPAN&gt; {&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; Close();&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P&gt;Simple enough, right? The conundrum arises when you have an object that implements both interfaces, &lt;STRONG&gt;and&lt;/STRONG&gt; uses the the same member to implement them, such as the following:&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;
&lt;TABLE class=MsoTableGrid style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BACKGROUND: white; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.45pt 5.75pt 1.45pt 5.75pt; mso-yfti-tbllook: 480; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext" cellSpacing=0 cellPadding=0 border=1&gt;
&lt;TBODY&gt;
&lt;TR style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"&gt;
&lt;TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.75pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.75pt; PADDING-BOTTOM: 1.45pt; BORDER-LEFT: windowtext 1pt solid; PADDING-TOP: 1.45pt; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt" vAlign=top&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;&lt;BR&gt;using&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt; Library;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;class&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt; &lt;SPAN style="COLOR: teal"&gt;NetworkSocket&lt;/SPAN&gt; : &lt;SPAN style="COLOR: teal"&gt;IResource&lt;/SPAN&gt;, &lt;SPAN style="COLOR: teal"&gt;IStream&lt;/SPAN&gt; {&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; Close() {&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;}&lt;BR style="mso-special-character: line-break"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;What struck &lt;EM&gt;me&lt;/EM&gt; as awkward, is that if you then&amp;nbsp;do "Find All References", on IStream.Close(), you'll get the following results:&lt;/FONT&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;(Definition) NetworkSocket.cs - (5,17): public void Close() {&lt;/FONT&gt; 
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;(Definition) IResource.cs - (5, 14): void Close();&lt;/FONT&gt; 
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;(Definition) IStream.cs - (5, 14): void Close();&lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Thus, intellisense reports that IStream.Close() is defined in all of those three places.&amp;nbsp; However, &lt;EM&gt;why is IResource.Close() in this list&lt;/EM&gt;?&amp;nbsp; Some IDE-team members argue that the design was that we would return the &lt;EM&gt;transitive closure&lt;/EM&gt; of all of the methods that are captured during this find process.&amp;nbsp; I, however, argue that this is definitely unintuitive.&amp;nbsp; This gets worse too, for example, introduce the following:&lt;/P&gt;
&lt;P&gt;
&lt;TABLE class=MsoTableGrid style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BACKGROUND: white; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.45pt 5.75pt 1.45pt 5.75pt; mso-yfti-tbllook: 480; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext" cellSpacing=0 cellPadding=0 border=1&gt;
&lt;TBODY&gt;
&lt;TR style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"&gt;
&lt;TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.75pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.75pt; PADDING-BOTTOM: 1.45pt; BORDER-LEFT: windowtext 1pt solid; PADDING-TOP: 1.45pt; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt" vAlign=top&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;using&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt; Library;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;class&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt; &lt;SPAN style="COLOR: teal"&gt;OtherResource&lt;/SPAN&gt; : &lt;SPAN style="COLOR: teal"&gt;IResource&lt;/SPAN&gt; {&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; Close() {&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;TABLE class=MsoTableGrid style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BACKGROUND: white; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.45pt 5.75pt 1.45pt 5.75pt; mso-yfti-tbllook: 480; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext" cellSpacing=0 cellPadding=0 border=1&gt;
&lt;TBODY&gt;
&lt;TR style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"&gt;
&lt;TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.75pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.75pt; PADDING-BOTTOM: 1.45pt; BORDER-LEFT: windowtext 1pt solid; PADDING-TOP: 1.45pt; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt" vAlign=top&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;using&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt; Library;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;class&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt; &lt;SPAN style="COLOR: teal"&gt;OtherStream&lt;/SPAN&gt; : &lt;SPAN style="COLOR: teal"&gt;IStream&lt;/SPAN&gt; {&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; Close() {&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;TABLE class=MsoTableGrid style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BACKGROUND: white; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.45pt 5.75pt 1.45pt 5.75pt; mso-yfti-tbllook: 480; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext" cellSpacing=0 cellPadding=0 border=1&gt;
&lt;TBODY&gt;
&lt;TR style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"&gt;
&lt;TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.75pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.75pt; PADDING-BOTTOM: 1.45pt; BORDER-LEFT: windowtext 1pt solid; PADDING-TOP: 1.45pt; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt" vAlign=top&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;using&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt; Library;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;class&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt; &lt;SPAN style="COLOR: teal"&gt;StreamReader&lt;/SPAN&gt; {&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; StreamReader(&lt;SPAN style="COLOR: teal"&gt;OtherStream&lt;/SPAN&gt; stream) {&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// ...read the stream ...&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;stream.Close();&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face=Verdana size=2&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face=Verdana size=2&gt;Now, invoke "Find All References" on &lt;STRONG&gt;IResource&lt;/STRONG&gt;.Close(). You'll get the following results:&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;(Definition) NetworkSocket.cs - (5,17): public void Close() {&lt;/FONT&gt; 
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;(Definition) OtherResource.cs - (5,17): public void Close() {&lt;/FONT&gt; 
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;(Definition) OtherStream.cs - (5,17): public void Close() {&lt;/FONT&gt; 
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;(Reference) StreamReader.cs - (6, 16) : stream.Close();&lt;/FONT&gt; 
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;(Definition) IResource.cs - (5, 14): void Close();&lt;/FONT&gt; 
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;(Definition) IStream.cs - (5, 14): void Close();&lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;IStream.Close() is on the list (which is the reverse case of the previous "strange" element), but what &lt;EM&gt;really&lt;/EM&gt; makes me think this is wrong, is that StreamReader's use of OtherStream is there.&amp;nbsp; OtherStream doesn't even implement IResource, so it's impossible for OtherStream.Close() to be related to IResource.Close().&amp;nbsp; In that context, you *know* you're &lt;STRONG&gt;not&lt;/STRONG&gt; dealing with an IResource, however, it's still a reference &amp;lt;shrug&amp;gt;.&amp;nbsp; This gets worse as you have more types that implement IResource or IStream, because whenever you do Find All References on Close(), you get even more unexpected results to wade through.&lt;BR&gt;&lt;BR&gt;So, you wonder, is there any&amp;nbsp;method behind the madness? It's all about Rename refactoring.&amp;nbsp; If you rename IStream.Close() to something else, you better rename IResource.Close() to the same thing, otherwise the NetworkSocket class will suddenly no longer implement all the members of IResource.&amp;nbsp; I think that's a valid concern, but IMHO, if you're sharing implementations on the same member, and then you rename one of the interfaces's declaration of that member, then I would &lt;STRONG&gt;expect&lt;/STRONG&gt; a compiler error to be introduced, saying that you can no longer implement both interfaces with the same member now.&amp;nbsp; Just because&amp;nbsp;one developer&amp;nbsp;happens to implement my interface, and someone else's interface, doesn't mean that if someone else renames their interface member that &lt;STRONG&gt;&lt;EM&gt;I too&lt;/EM&gt;&lt;/STRONG&gt; should be renamed.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;So, mine is obviously a directed perspective, but how do the rest of you out there feel about this?&lt;/FONT&gt;&lt;/o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=436254" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/theoy/archive/tags/OO+Design+101/default.aspx">OO Design 101</category><category domain="http://blogs.msdn.com/theoy/archive/tags/Random+.NET+Platform/default.aspx">Random .NET Platform</category><category domain="http://blogs.msdn.com/theoy/archive/tags/C_2300_+IDE/default.aspx">C# IDE</category></item><item><title>Referring to "value types" versus "reference types", Part 2</title><link>http://blogs.msdn.com/theoy/archive/2005/06/28/ValueRef2.aspx</link><pubDate>Tue, 28 Jun 2005 23:31:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:433163</guid><dc:creator>TheoY</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.msdn.com/theoy/comments/433163.aspx</comments><wfw:commentRss>http://blogs.msdn.com/theoy/commentrss.aspx?PostID=433163</wfw:commentRss><description>&lt;P dir=ltr style="MARGIN-RIGHT: 0px"&gt;&lt;FONT face=Verdana color=#000000 size=2&gt;Last Friday, I blogged about confusion between the terms "value" and "reference", when relating to .NET development.&amp;nbsp; The post can be found here:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;a href="http://blogs.msdn.com/theoy/archive/2005/06/24/ValueRef.aspx"&gt;&lt;FONT face=Verdana size=2&gt;http://blogs.msdn.com/theoy/archive/2005/06/24/ValueRef.aspx&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;This time, I'm continuing the discussion specifically relating to &lt;STRONG&gt;value types&lt;/STRONG&gt; and &lt;STRONG&gt;reference types&lt;/STRONG&gt;.&amp;nbsp; After this, passing by value / passing by reference will be covered, as well as referring to an object's "value" or its "reference". So, continuing... I left off stating that I still have the following topics to cover, as part of &lt;EM&gt;Referring to "value types" versus "reference types"&lt;/EM&gt;:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;(1) Enums&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;(2) Type unification, boxing/unboxing&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;(3) Interfaces and inheritance for value types&lt;BR&gt;&lt;BR&gt;&lt;STRONG&gt;Enums&lt;BR&gt;&lt;BR&gt;&lt;/STRONG&gt;.NET has built-in support for a special kind of type, called an &lt;EM&gt;enum type&lt;/EM&gt;.&amp;nbsp; Enums are also value types, and have all of the traits that I described for value types in the previous blog entry, except for some&amp;nbsp;small differences that are not relevant to this topic.&amp;nbsp; One way to look at them is as &lt;EM&gt;specialized&lt;/EM&gt; value types.&amp;nbsp; For example, .NET enum types don't have instance fields, nor methods or&amp;nbsp;properties.&amp;nbsp; Basically they exist so that one can specify names for what would otherwise be numeric values.&amp;nbsp; Their syntax is as follows:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT face=Verdana color=#000000 size=2&gt;C#/J#:&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT face=Verdana size=2&gt;&lt;BR&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;enum&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face=Verdana size=2&gt; &lt;FONT color=#008080&gt;MyEnumType&lt;/FONT&gt; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT face=Verdana size=2&gt;VB.NET (requires all&amp;nbsp;enum types define at least one value):&lt;BR&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;Enum&lt;/FONT&gt; MyEnumType&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; OneSampleValue&lt;BR&gt;&lt;/FONT&gt;&lt;FONT face=Verdana size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT face=Verdana size=2&gt;End&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT face=Verdana&gt; &lt;FONT color=#0000ff&gt;Enum&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Each of the languages will automatically assign values to the enums if you don't care, but also will let you define specific values to assign to their corresponding names if you wish.&amp;nbsp; As you'd expect, they all compile down to the same thing under the hood, which is one of the reasons why .NET language integration is so streamlined between C#/VB/J#.&amp;nbsp; However, when contrasting value types and reference types, a user only needs to know that enums are in the "value types" camp.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;STRONG&gt;Type Unification, Boxing and Unboxing&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;This is when it gets a little hairy... so in the first article, I described value types getting allocated on the stack, and reference types on the heap.&amp;nbsp; However, there are some leftover questions that you're probably pondering, such as:&lt;BR&gt;&lt;BR&gt;(1) If anything that &lt;STRONG&gt;doesn't&lt;/STRONG&gt; extend from System.ValueType is a reference type, then how does the CLR tell the difference between value types and the rest of the types that descend directly/indirectly from System.Object?&lt;BR&gt;(2) How do value types implement interfaces, and how are those interface implementations distinguished between those of reference types?&lt;BR&gt;(3) Is System.ValueType itself, a value type or a reference type?&lt;BR&gt;&lt;BR&gt;Those are all good questions, and require understanding of the CLR type unification system.&amp;nbsp; Java has less of this to worry over, since it doesn't support custom value types (it only supports its built-in "primitive types").&amp;nbsp; In fact, prior to Java 1.5/5.0, users had to explicitly convert their primitive types to their corresponding wrapper objects (e.g. java.lang.Integer).&amp;nbsp; In addition, users of reflection on Java would have to deal with two different class objects for each primitive and its corresponding wrapped type.&amp;nbsp; Not fun.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Thus for .NET, there came a need to unify this more - and they introduced a concept of boxing and unboxing.&amp;nbsp; You can think of boxing and unboxing as being another special form of copying, for a value type (in fact, one &lt;EM&gt;must&lt;/EM&gt; realize that boxing and unboxing performs copies).&amp;nbsp; However, the distinction between boxing and unboxing from other forms of copying (say assignment, parameter passing or receiving return value) is that boxing places a value type inside a wrapper (a "box") where it *then* behaves like a &lt;STRONG&gt;heap object&lt;/STRONG&gt;.&amp;nbsp; By wrapping value types&amp;nbsp;as heap objects, they can then be treated the same way as other heap objects.&amp;nbsp;&amp;nbsp;.NET has built-in support for&amp;nbsp;object-oriented type systems - and likewise has to implement virtual methods similar to pre-.NET C++, and Java.&amp;nbsp; You probably guessed that virtual methods require some sort of special handling, that makes them different from non-virtual methods.&amp;nbsp; Since any subclass an override a non-sealed virtual method, there needs to be some infrastructure to look up which function to actually run.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;The way that those usually work is that an object in memory usually has a pointer (just an address value to some other chunk of memory) that points back to a shared virtual method table (or &lt;EM&gt;v-table&lt;/EM&gt;), since in .NET and Java, overriding a method overrides it for all instances of that type.&amp;nbsp; Then the object can be passed around as any super type that it implements, and when a function call is required, a lookup of the appropriate index in the v-table will allow for code to pick up the overriden method.&amp;nbsp; As long as the means to access the v-table pointer are consistent, and the indices are consistent, then a function for one type need not worry about if it is executing on object that's actually an instance of a subclass.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;This is all fine and dandy, but once you're passing around pointers to objects, and you're trying to avoid examining what type they really are, then how do you know if you're dealing with an implementation derived from a value type, or a reference type? The answer is, by default, &lt;STRONG&gt;you don't&lt;/STRONG&gt;.&amp;nbsp; That's why value types &lt;STRONG&gt;&lt;EM&gt;need&lt;/EM&gt;&lt;/STRONG&gt; to be boxable into heap objects, so that code that consumes any interfaces that they implement may be able to dispatch off of those objects without having to concern themselves on whether or not that object is a value type or reference type.&amp;nbsp; Thus, it makes things easier to realize that when dealing with objects at an interface type-level, you're always dealing with heap objects - either reference type objects, or boxed value type objects.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;The reason why I discuss "unification" is that in .NET, this wrapped value type support is automatically generated for you whenever you define a new value type.&amp;nbsp; It would be a nightmare if each user had to define their own heap wrapper type for every new value type they defined.&amp;nbsp; That's why Java's explicit type wrappers aren't a scalable solution if they were to allow users to define their own primitives.&amp;nbsp; Also, when using reflection, boxed and unboxed value types share the same type object (e.g. if you use C#'s typeof() keyword).&amp;nbsp; This means that if you're dealing with boxed or unboxed objects using reflection, you can confidently know that testing them against a type object will do what you'd expect (another issue with Java's having two separate class objects for wrapped and unwrapped primitives).&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;The last tricky part is that the type,&amp;nbsp;System.ValueType &lt;EM&gt;itself&lt;/EM&gt;, is &lt;STRONG&gt;not&lt;/STRONG&gt; a value type.&amp;nbsp; Users can only create objects of types that &lt;EM&gt;derive&lt;/EM&gt; from System.ValueType, and using a value type as an instance of System.ValueType causes it to be boxed.&amp;nbsp; The reason why is that once you're dealing with a value type at the System.ValueType level, you have very little knowledge remaining about the value type (for example, you have no idea what fields it has).&amp;nbsp; All you have are virtual methods that you can call, which require boxing, as you'd expect.&amp;nbsp; The same thing applies to System.Enum - once you're dealing with an enum value at the System.Enum level, you're actually dealing with a &lt;EM&gt;boxed enum&lt;/EM&gt;.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;As you can tell, System.ValueType and System.Enum have to be special-cased in the runtime, as their descendents are all value types.&amp;nbsp; In my opinion, there's not really a great way to structure them in the inheritance tree, but here's how they're structured in reality: (go, go, ascii art)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;&lt;FONT color=#808080&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;&lt;FONT face=Verdana&gt;&lt;FONT color=#000000&gt;System.&lt;/FONT&gt;&lt;FONT color=#008080&gt;Object&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;|&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;+- &lt;FONT color=#000080&gt;&lt;FONT face=Verdana color=#008080&gt;&lt;STRONG&gt;&lt;FONT color=#000000&gt;System.&lt;/FONT&gt;ValueType&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;/FONT&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;|&amp;nbsp;&amp;nbsp;&amp;nbsp;|&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;|&amp;nbsp;&amp;nbsp;&amp;nbsp;+- &lt;FONT face=Verdana color=#008080&gt;&lt;STRONG&gt;&lt;FONT color=#000000&gt;System.&lt;/FONT&gt;Enum&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;|&amp;nbsp;&amp;nbsp;&amp;nbsp;|&amp;nbsp;&amp;nbsp;&amp;nbsp;|&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;|&amp;nbsp;&amp;nbsp;&amp;nbsp;|&amp;nbsp;&amp;nbsp;&amp;nbsp;+- &lt;FONT face=Verdana color=#000080&gt;&lt;STRONG&gt;&amp;lt;all enum-types&amp;gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;|&amp;nbsp;&amp;nbsp;&amp;nbsp;|&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;|&amp;nbsp;&amp;nbsp;&amp;nbsp;+- &lt;FONT face=Verdana color=#000080&gt;&lt;STRONG&gt;&amp;lt;all-non-enum-value-types&amp;gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;|&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;+- &lt;/FONT&gt;&lt;FONT face=Verdana color=#008080&gt;&lt;STRONG&gt;&amp;lt;all-other-reference-types&amp;gt;&lt;BR&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT face=Verdana size=2&gt;I use VS 2005 (Beta2 is pretty stable) when I code, and one of the things that I always change first is the fonts and colors preferences.&amp;nbsp; I set VS to colorize all enums and value types in navy, instead of teal, so that I can notice what my code is doing, and whether or not I'm going to copy, box, or&amp;nbsp;unbox.&amp;nbsp; As you can see, I've actually colorized the types System.ValueType and System.Enum in teal, because those types specifically, are actually reference types.&amp;nbsp; It's their derived types that are value types.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;FONT face=Verdana size=2&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;STRONG&gt;Interface inheritance for Value types&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Users defining their own value types will notice that they can specify interfaces for their value types to implement.&amp;nbsp; Yes, this is a powerful corollary to the unification described previously.&amp;nbsp; When transferred to a context that requires an interface to be implemented, value types get boxed, and are then indistinguishable from reference types, to the interface consumers.&amp;nbsp; What I mean by indistinguishable is that consumers needn't worry if they're dealing with value types or reference types - but they can of course query if the object in question also extends from System.ValueType (e.g. in C#, using the "is"/"as" keyword).&lt;/P&gt;
&lt;P&gt;I think that pretty well summarizes most of the important differences between value types and reference types.&amp;nbsp; In the queue of topics to cover in my future blog posts will be some best-practices for value types.&lt;/P&gt;&lt;/FONT&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=433163" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/theoy/archive/tags/Random+.NET+Platform/default.aspx">Random .NET Platform</category></item><item><title>"Value" and "Reference" Confusion</title><link>http://blogs.msdn.com/theoy/archive/2005/06/24/ValueRef.aspx</link><pubDate>Fri, 24 Jun 2005 23:29:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:432353</guid><dc:creator>TheoY</dc:creator><slash:comments>9</slash:comments><comments>http://blogs.msdn.com/theoy/comments/432353.aspx</comments><wfw:commentRss>http://blogs.msdn.com/theoy/commentrss.aspx?PostID=432353</wfw:commentRss><description>&lt;P&gt;&lt;FONT face=Verdana size=2&gt;While talking to someone yesterday, I witnessed yet another instance of "value" versus "reference" confusion.&lt;BR&gt;&lt;BR&gt;What do I mean? This is particularly confusing in .NET, because of some probably mistaken jargon choices on Microsoft's behalf.&amp;nbsp; Commonly in .NET, the terms "value" and "reference" come up in these contexts:&lt;BR&gt;(1) Discerning between "value types" and "reference types"&lt;BR&gt;(2) Discerning between "pass by value" and "pass by reference"&lt;BR&gt;(3) Referring to an object's "value" or "reference".&lt;BR&gt;&lt;BR&gt;I don't blame anyone when they get confused by these terms, I mean - when someone discusses .NET with me, and mentions "value" or "reference", I often end up asking them to disambiguate in which context they are referring.&amp;nbsp; I'll have examples in C#, VB, and J#&amp;nbsp;in this post, to help people associate what I'm discussing with the actual code that they've probably seen.&lt;BR&gt;&lt;BR&gt;&lt;FONT size=3&gt;&lt;B&gt;1. Referring to "value types"&amp;nbsp;versus "reference types"&lt;/B&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;BR&gt;This is &lt;I&gt;probably&lt;/I&gt; the most common need to actually discern between the two, and is greatly associated with other .NET concepts such as nullity, boxing, heap vs. stack allocation, virtual methods, and tons of other things.&amp;nbsp; For Java users, the term "primitive" is synonymous with .NET's "value type" term.&amp;nbsp; What this means, is that a &lt;I&gt;value type&lt;/I&gt; is what the CLR/CPU actually end dealing with when it comes down to performing computations, and comparisons.&lt;BR&gt;&lt;BR&gt;Users familiar with how a program works are probably also familiar with the term program "stack" versus "heap".&amp;nbsp; Unfamiliar users need only understand some basic distinctions between the two:&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (1) They're both sections of memory in a program, but are allocated and treated in different manners.&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (2) The program "stack" is a memory section that exists for the currently executing part of the program, and typically holds reserved space for local variables.&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (3) The program "heap" is a part that contains reserved memory that might persist past the current function, thread, and possibly persist the entire lifetime of the program.&amp;nbsp; In some programs, there are other parts of memory that persist throughout the program, but this is the one that you'll be dealing with the most in .NET.&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (4) Memory reserved in the program stack, for a particular function, is reclaimed / reused automatically when the function returns.&amp;nbsp; If the function A calls function B before returning, function A's stack memory will persist all the way through until function A finishes, including the portion of the time that function B is being executed.&lt;BR&gt;&lt;BR&gt;Now "objects" and "classes" are all about two things: containing things in memory, and inheritance.&amp;nbsp; The characteristics of these memory sections are &lt;I&gt;extremely important&lt;/I&gt; with deciding how an object needs to be treated.&amp;nbsp; Here're the differences now, between "value types" and "reference types".&lt;BR&gt;&lt;BR&gt;Under the hood, "reference types" are &lt;B&gt;always&lt;/B&gt; allocated on the program &lt;B&gt;heap&lt;/B&gt;.&amp;nbsp; When the CLR decides to make one, it first chunks out the appropriate amount of memory on the heap before running the constructor.&amp;nbsp; Whoever called for the creation of an instance of this reference type will then get back the "pointer", or the address of the object's memory in the heap.&amp;nbsp; Everywhere that consumes this type will deal exclusively with addresses to heap memory.&amp;nbsp; Most of the classes/types in .NET are reference types.&amp;nbsp; You declare a new reference type in C#, VB.NET, and J# using the "class" keyword.&amp;nbsp; If I wanted to define a reference type called "MyReferenceType", I'd use the following syntaxes:&lt;BR&gt;&lt;BR&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT face=Verdana&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;C#/J#:&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;FONT color=#0000ff size=2&gt;class&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#008080 size=2&gt;MyReferenceType&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT face=Verdana&gt; {&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face=Verdana size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;VB.NET:&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;FONT face=Verdana size=2&gt;&lt;FONT color=#0000ff size=2&gt;Class&lt;/FONT&gt;&lt;FONT size=2&gt;&amp;nbsp;MyReferenceType&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face=Verdana size=2&gt;&lt;FONT color=#0000ff size=2&gt;End&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Class&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;The above three examples do / compile-to the exact same thing.&amp;nbsp; Now, &lt;EM&gt;value types&lt;/EM&gt; differ in the way that you probably guessed... they're allocated out of the stack.&amp;nbsp; That means that when a function executes, all of the value types it uses are known before hand, and are laid out before execution actually begins in the function.&amp;nbsp; It also means that the memory allocated for them must go away when the function finishes (returns).&amp;nbsp; However, there are a couple of things that must be done in order to keep&amp;nbsp;the CLR&amp;nbsp;a safe/managed environment.&lt;/P&gt;
&lt;P&gt;If you're using a value type in your function, how can you return it to your caller, if the memory allocated goes away/gets reused? Obviously that wouldn't be safe.&amp;nbsp; The way that this is resolved is that functions can only return a &lt;STRONG&gt;copy&lt;/STRONG&gt; of that memory.&amp;nbsp; Likewise, when you pass a value type to a function, by default (I'll explain later in this post), it's&amp;nbsp;&lt;STRONG&gt;copied&lt;/STRONG&gt;.&amp;nbsp; This is a simpler allocation and reclamation process than heap objects (which are reclaimed by the garbage collector), so it's often faster.&amp;nbsp; However, it's only faster for small objects - otherwise all of the copying catches up with you.&amp;nbsp; In fact, your basic types are all value types - for example, the "&lt;FONT color=#0000ff size=2&gt;int&lt;/FONT&gt;" in C#/J# and&amp;nbsp;VB's "&lt;FONT color=#0000ff size=2&gt;Integer&lt;/FONT&gt;" are&amp;nbsp;value types.&amp;nbsp; You can declare your own custom value type in the following syntax:&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;C#:&lt;BR&gt;&lt;FONT color=#0000ff size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;struct&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#008080 size=2&gt;MyValueType&lt;/FONT&gt;&lt;FONT size=2&gt; {&lt;BR&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;VB.NET: (requires all&amp;nbsp;value types have at least one field)&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;FONT color=#0000ff size=2&gt;Structure&lt;/FONT&gt;&lt;FONT size=2&gt; MyValueType&lt;BR&gt;&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Private&lt;/FONT&gt;&lt;FONT size=2&gt; SampleField &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Integer&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;End&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Structure&lt;BR&gt;&lt;/FONT&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;J#: (requires all value types to explicitly extend from System.&lt;FONT color=#008080&gt;ValueType&lt;/FONT&gt;)&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;FONT color=#0000ff size=2&gt;import&lt;/FONT&gt;&lt;FONT size=2&gt; System.*;&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;final&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;class&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#008080 size=2&gt;MyValueType&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;extends&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#008080 size=2&gt;ValueType&lt;/FONT&gt;&lt;FONT size=2&gt; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/P&gt;
&lt;P&gt;The VS 2005 C# IDE provides the additional feature that people can invoke the "Go to Definition" command on any of the built-in types, as if they were defined by your source code.&amp;nbsp; If that's the case, you'll see a file that's generated on the fly, that's in a C#-like syntax.&amp;nbsp; For example, "Go to Definition" on "&lt;FONT color=#0000ff size=2&gt;int&lt;/FONT&gt;", in C# for VS 2005, brings me to:&lt;/FONT&gt;&lt;BR&gt;&lt;BR&gt;&lt;FONT color=#0000ff size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;namespace&lt;/FONT&gt;&lt;FONT size=2&gt; System {&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;struct&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#008080 size=2&gt;Int32&lt;/FONT&gt;&lt;FONT size=2&gt; : &lt;/FONT&gt;&lt;FONT color=#008080 size=2&gt;IComparable&lt;/FONT&gt;&lt;FONT size=2&gt;, &lt;/FONT&gt;&lt;FONT color=#008080 size=2&gt;IFormattable&lt;/FONT&gt;&lt;FONT size=2&gt;, &lt;/FONT&gt;&lt;FONT color=#008080 size=2&gt;IConvertible&lt;/FONT&gt;&lt;FONT size=2&gt;, &lt;/FONT&gt;&lt;FONT color=#008080 size=2&gt;IComparable&lt;/FONT&gt;&lt;FONT size=2&gt;&amp;lt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;int&lt;/FONT&gt;&lt;FONT size=2&gt;&amp;gt;, &lt;/FONT&gt;&lt;FONT color=#008080 size=2&gt;IEquatable&lt;/FONT&gt;&lt;FONT size=2&gt;&amp;lt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;int&lt;/FONT&gt;&lt;FONT size=2&gt;&amp;gt; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;...&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;Which allows you to see that "&lt;FONT color=#0000ff size=2&gt;int&lt;/FONT&gt;" is really an alias for "System.&lt;FONT color=#008080&gt;Int32&lt;/FONT&gt;&lt;FONT size=2&gt;", which is a value type since it uses the &lt;FONT color=#0000ff&gt;struct&lt;/FONT&gt; syntax.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;So, this is just a starter on the difference between value types and reference types,&amp;nbsp;but I'm taking a break.&amp;nbsp; Some more things that I'll cover in my next post, before finishing this point are:&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;(1) Enums&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;(2) Type unification, boxing/unboxing&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;(3) Interfaces and inheritance for value types&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=432353" width="1" height="1"&gt;</description></item><item><title>Comparing C# and VB.NET</title><link>http://blogs.msdn.com/theoy/archive/2005/06/20/430838.aspx</link><pubDate>Mon, 20 Jun 2005 23:05:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:430838</guid><dc:creator>TheoY</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/theoy/comments/430838.aspx</comments><wfw:commentRss>http://blogs.msdn.com/theoy/commentrss.aspx?PostID=430838</wfw:commentRss><description>&lt;P&gt;&lt;FONT face=Verdana size=2&gt;A reader wrote me just now:&lt;/FONT&gt;&lt;/P&gt;
&lt;BLOCKQUOTE dir=ltr&gt;
&lt;P&gt;&lt;FONT face=Tahoma color=#a52a2a size=2&gt;Hi,&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Tahoma color=#a52a2a size=2&gt;I just came across your blog and seeing that you're mentioning random thoughs on .NET, I was hoping you'd be able to answer this question: Is there any real difference to coding in VB or in C# when it comes to the .NET framework? If there are differences, do they still exist when I narrow the topic down to .NET web applications?&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Tahoma color=#a52a2a size=2&gt;Thanks,&lt;BR&gt;Max&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;When it comes down to it, in my opinion, there aren't many significant language differences between VB.NET and C#.&amp;nbsp; Most of the constructs in those languages are achievable from the other language, which is why you'll often see samples online in both languages.&amp;nbsp; I think VB.NET includes more implicit conversion operators, as well as a bunch of other constructs if you disable option-strict compiling (such as late-binding).&amp;nbsp; C#, as a language, will generally be more explicit than VB.&amp;nbsp; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;With VS 2005 (C# 2.0), C# includes anonymous methods, which are not a VB construct - VB users can workaround it by declaring new types/methods as necessary (which is what the C# compiler does under the hood).&amp;nbsp; C# 2.0 also supports new iterator methods (using the yield keyword), which I think is unsupported by VB.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;VB includes a ton of "built-in" functions, which usually delegate to other .NET framework library functions that are accessible by C#.&amp;nbsp; Because of that, VB programs load several .NET framework DLL's that are not always needed in all programs, but are required for supporting VB built-in functions.&amp;nbsp; In C#, a lot of what the language does to supplement the .NET Framework isn't providing specific built-in functions per se, but more language features, that affect the way your code is compiled (instead of introducing other dependencies).&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;In regards to ASP.NET and web applications, I don't think that the above discussion applies any differently - the ASP.NET integration should be nearly identical for both languages.&amp;nbsp; Any preference towards choosing VB over C# or vice versa will probably be off of developer's taste.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;I'm sure other folks out there will point out other important differences between C# and VB, but these are the ones that come to mind.&lt;BR&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=430838" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/theoy/archive/tags/Random+.NET+Platform/default.aspx">Random .NET Platform</category></item><item><title>Re-commission</title><link>http://blogs.msdn.com/theoy/archive/2005/06/20/recommission.aspx</link><pubDate>Mon, 20 Jun 2005 21:07:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:430793</guid><dc:creator>TheoY</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/theoy/comments/430793.aspx</comments><wfw:commentRss>http://blogs.msdn.com/theoy/commentrss.aspx?PostID=430793</wfw:commentRss><description>&lt;P&gt;&lt;FONT face=Verdana size=2&gt;So after a super long hiatus, I've finally admitted that I'll end up posting far too infrequently if I restrict myself to writing a purely technical column.&amp;nbsp; I mean, for technical posts, there's a lot of vetting that I put myself through in order to be very confident in my posts (and still trying to maintain as semblance of working full-time as a developer).&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Therefore, it's probably best that I re-commission this blog for more than just covering OO and .NET ideas, but also covering my perspective on working at MS / Developer Division / C#.&amp;nbsp; I've also been solicited by some friends that are interested in programming, that maybe I begin a blog that covers programming 101, similar to a computer science course, and of course, using C# :)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;So here goes - and I hope you guys like the new feel of my blog.&amp;nbsp; Oh, the explanation of the new title - you've probably guessed that's it's a reference to music in some way... the music theory nerds out there will probably know that the only accidental (sharp or flat note) in the ascending D melodic minor scale is the C# accidental.&amp;nbsp; I guess the esoteric title is partly a rejection, on my behalf,&amp;nbsp;over the need for titles :)&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=430793" width="1" height="1"&gt;</description></item><item><title>Transitioning</title><link>http://blogs.msdn.com/theoy/archive/2004/11/18/266161.aspx</link><pubDate>Fri, 19 Nov 2004 03:58:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:266161</guid><dc:creator>TheoY</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/theoy/comments/266161.aspx</comments><wfw:commentRss>http://blogs.msdn.com/theoy/commentrss.aspx?PostID=266161</wfw:commentRss><description>&lt;p&gt;&lt;font face="Verdana" size="2"&gt;Some personal news: &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Verdana" size="2"&gt;I've recently accepted an offer to&amp;nbsp;develop for&amp;nbsp;the C# IDE team (exact switch-date TBD).&amp;nbsp; This would have me working on the same dev team with some of your likely familiar bloggers:&lt;/font&gt;&lt;/p&gt; &lt;ul&gt; &lt;li&gt;&lt;font face="Verdana" size="2"&gt;Cyrus: &lt;A href="http://blogs.msdn.com/cyrusn/"&gt;http://blogs.msdn.com/cyrusn/&lt;/a&gt;&lt;/font&gt;&lt;/li&gt; &lt;li&gt;&lt;font face="Verdana" size="2"&gt;Kevin: &lt;a href="http://weblogs.asp.net/kevinpilchbisson"&gt;http://weblogs.asp.net/kevinpilchbisson&lt;/a&gt;&lt;/font&gt;&lt;/li&gt; &lt;li&gt;&lt;font face="Verdana" size="2"&gt;Jay (to be manager): &lt;A href="http://blogs.msdn.com/jaybaz_ms/"&gt;http://blogs.msdn.com/jaybaz_ms/&lt;/a&gt;&lt;/font&gt;&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;font face="Verdana" size="2"&gt;and of course, there's Anson (&lt;A href="http://blogs.msdn.com/ansonh"&gt;http://blogs.msdn.com/ansonh&lt;/a&gt;),&amp;nbsp;a trusty IDE program manager.&amp;nbsp; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Verdana" size="2"&gt;Things are still TBD on exactly what I'd be working on within the IDE, but I'm looking forward to the change of scenery and with working with these great people :)&lt;/font&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=266161" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/theoy/archive/tags/Personal/default.aspx">Personal</category></item><item><title>.NET Framework SP's Available!</title><link>http://blogs.msdn.com/theoy/archive/2004/08/30/222998.aspx</link><pubDate>Tue, 31 Aug 2004 00:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:222998</guid><dc:creator>TheoY</dc:creator><slash:comments>11</slash:comments><comments>http://blogs.msdn.com/theoy/comments/222998.aspx</comments><wfw:commentRss>http://blogs.msdn.com/theoy/commentrss.aspx?PostID=222998</wfw:commentRss><description>&lt;font face="Verdana" size="2"&gt; &lt;p&gt;For those who haven't gotten their hands on an Windows XPSP2 CD,&amp;nbsp;new .NET Framework SP's are now available, for versions 1.0 and 1.1 (the first version of 2.0, or "Whidbey" is still yet to be released).&lt;/p&gt; &lt;p&gt;Here are the links to Microsoft's download center, the related "Knowledge Base" links may not become active on the web for a couple hours.&amp;nbsp; When they become active, you'll be able to see a list of fixes included in these service packs.&amp;nbsp; Rest assured, these patches are a culmination of a ton of work (by&amp;nbsp;the&amp;nbsp;.NET Framework&amp;nbsp;team, and my team).&amp;nbsp; In a couple of days, they should also become available via &lt;a href="http://www.windowsupdate.com"&gt;Windows Update&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;.NET Framework Version 1.1&lt;/strong&gt;&lt;br /&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=A8F5654F-088E-40B2-BBDB-A83353618B38"&gt;Service Pack 1 for All OS's other than Windows Server 2003&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=AE7EDEF7-2CB7-4864-8623-A1038563DF23"&gt;Service Pack 1 for Windows Server 2003&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;.NET Framework Version 1.0&lt;br /&gt;&lt;/strong&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=6978D761-4A92-4106-A9BC-83E78D4ABC5B"&gt;Service Pack 3 for All OS's other than XP for Tablet PC / Media Center&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Notice there are two links for the 1.1 version: it's because the .NET Framework is installed via Windows Installer technology on most operating systems, but is incorporated as an OS component for Windows Server 2003.&lt;/p&gt; &lt;p&gt;Likewise, 1.0 .NET Framework was incorporated as part of the XP version for Tablet PC / Media Center.&amp;nbsp; So those users will actually get SP3 for the 1.0 .NET Framework by simply installing XPSP2.&lt;/p&gt; &lt;p&gt;If you're running Windows Server 2003, you should reboot after installing the 1.1 Framework SP in case some files (e.g. DLL's in the CLR and base class libraries) were in use during installation.&amp;nbsp; The patch on Windows Update will always ask for reboot for the 1.1 SP1 patch.&lt;/p&gt;&lt;/font&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=222998" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/theoy/archive/tags/Random+.NET+Platform/default.aspx">Random .NET Platform</category></item><item><title>More Singleton</title><link>http://blogs.msdn.com/theoy/archive/2004/05/21/136610.aspx</link><pubDate>Fri, 21 May 2004 10:29:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:136610</guid><dc:creator>TheoY</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/theoy/comments/136610.aspx</comments><wfw:commentRss>http://blogs.msdn.com/theoy/commentrss.aspx?PostID=136610</wfw:commentRss><description>&lt;FONT size=2&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;/P&gt;&lt;/FONT&gt;
&lt;P&gt;&lt;FONT size=2&gt;Ok, so I lied: I'm not moving on to unions quite yet.&amp;nbsp; &lt;A href="http://blogs.msdn.com/cyrusn/archive/2004/05/21/136560.aspx"&gt;Cyrus&lt;/A&gt; brought up a great point on the last post about .NET serialization, as well as the lack of thread safety in my third example.&amp;nbsp; Due to the shared nature of singletons, I have to agree that thread-safety is an important enough requirement to mandate an expansion of the singleton story...&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;In addition, Andrew provided a great link about some other thoughts on implementing singletons in .NET.&lt;BR&gt;&lt;BR&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;A href="http://www.yoda.arachsys.com/csharp/singleton.html" target=_new&gt;&lt;FONT color=#cc0000&gt;http://www.yoda.arachsys.com/csharp/singleton.html&lt;/FONT&gt;&lt;/A&gt;&lt;BR&gt;&lt;BR&gt;It introduces a neat way to resolve the thread safety by relying on the lazy loading of types in .NET.&amp;nbsp; Although the article from arachsys.com doesn't mention serialization, if you read the MSDN reference on &lt;A href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemruntimeserializationserializationinfoclasstopic.asp "&gt;System.Runtime.Serialization.SerializationInfo&lt;/A&gt;, its example includes a way to control reinstantiation during deserialization in order to obtain the shared instance instead of the default serialization behavior of invoking a constructor.&amp;nbsp; In doing so, you have to create a type that proxies for you during serialization -- but there's no reason why it shouldn't be the same nested type used for delay loading of the lazy-shared instance.&amp;nbsp; Thus, whip in some explicit interface implementations (comment if you really want me to cover this topic), and voila!, you get the following:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;
&lt;TABLE class=MsoTableGrid style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BACKGROUND: white; BORDER-LEFT: medium none; WIDTH: 100%; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 5.75pt 5.75pt 5.75pt 5.75pt; mso-yfti-tbllook: 480; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext" cellSpacing=0 cellPadding=0 width="100%" border=1&gt;
&lt;TBODY&gt;
&lt;TR style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"&gt;
&lt;TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.75pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.75pt; PADDING-BOTTOM: 5.75pt; BORDER-LEFT: windowtext 1pt solid; WIDTH: 100%; PADDING-TOP: 5.75pt; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt" vAlign=top width="100%"&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;[Serializable]&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Lucida Console'"&gt;sealed&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt; &lt;SPAN style="COLOR: blue"&gt;class&lt;/SPAN&gt; Foo : ISerializable {&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// change the default constructor to private&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; Foo() { }&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;static&lt;/SPAN&gt; Foo Only {&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt; { &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; SerializationProxy.sharedOnly; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; DoFunctionality();&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;[Serializable]&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;class&lt;/SPAN&gt; SerializationProxy : IObjectReference {&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;internal&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;static&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;readonly&lt;/SPAN&gt; Foo sharedOnly = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; Foo();&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; IObjectReference.GetRealObject(StreamingContext context) {&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// When deserializing this object, return a reference to &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// Foo's singleton object instead.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; sharedOnly;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;[SecurityPermission(SecurityAction.Demand,SerializationFormatter=&lt;SPAN style="COLOR: blue"&gt;true&lt;/SPAN&gt;)]&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) {&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;info.SetType(&lt;SPAN style="COLOR: blue"&gt;typeof&lt;/SPAN&gt;(Foo.SerializationProxy));&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT size=2&gt;The example differs from both the MSDN example and the arachsys.com article, but I'm pretty convinced it's the right thing to do.&amp;nbsp; Creating a new type for serialization proxying is pretty much necessary unless you want to change the constructor semantics for the singleton type itself.&amp;nbsp; Consider the following:&lt;BR&gt;&lt;BR&gt;Assume type Foo is its own serialization proxy.&amp;nbsp; During deserialization, the proxy instance of Foo is deserialized by default serialization means -- which involves invoking some constructor (either compiler provided default constructor, or user-coded).&amp;nbsp; Thus you lose the invariant that any instance constructor is only invoked &lt;STRONG&gt;once&lt;/STRONG&gt;, since &lt;EM&gt;some&lt;/EM&gt; instance constructor has to be invoked at every proxy deserialization before GetRealObject() is invoked on the proxy. &lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT size=2&gt;&lt;/FONT&gt;&lt;/o:p&gt;&amp;nbsp;&lt;/P&gt;&lt;o:p&gt;&lt;FONT size=2&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT size=2&gt;It seems&amp;nbsp;better to &amp;#8220;de-singleton&amp;#8221; the proxy type and hide it away, and a private nested type comes natural to my mind.&amp;nbsp; Since it's nested, it allows us to also follow the arachsys.com and change the loading of the actual singleton instance to a form of "lazy loading", without ever having to introduce a synchronization keyword (e.g. "&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Lucida Console'; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA; mso-bidi-font-family: 'Times New Roman'"&gt;lock&lt;/SPAN&gt;&lt;FONT color=#0000ff size=2&gt;&lt;/FONT&gt;") or use the synchronization API.&amp;nbsp; Albeit, the code doesn't really reflect in its structure that it's particularly both threadsafe and lazy-loading.&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;So, why do we &lt;EM&gt;really&lt;/EM&gt; have to worry about serialization? Mostly because any of these implementations only guarantee one instance per &lt;STRONG&gt;&lt;EM&gt;AppDomain&lt;/EM&gt;&lt;/STRONG&gt;, which is somewhat like a process-like abstraction for .NET, except you can have more than one AppDomain per process.&amp;nbsp; Each AppDomain has its own copies of static data though, so you can shield the effects on one against the other.&amp;nbsp; Sometimes this is what you want to do (say you're running some untrusted code).&amp;nbsp; However, this also prevents them from really sharing singleton instances.&amp;nbsp; Also, when you have two .NET programs communicating across different processes (either concurrently, or different invocations using saved state), or on different computers, serialization becomes key.&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT size=2&gt;I still probably use, in practice, the first or second simplistic singleton implementation -- with the addition of serialization support if necessary... but covering this topic has definitely brought new light to my own design toolbox -- I'll probably opt for this nested-lazy-serializable implementation a lot more in the future.&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=136610" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/theoy/archive/tags/OO+Design+101/default.aspx">OO Design 101</category></item><item><title>Singleton Pattern</title><link>http://blogs.msdn.com/theoy/archive/2004/05/20/136528.aspx</link><pubDate>Fri, 21 May 2004 06:50:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:136528</guid><dc:creator>TheoY</dc:creator><slash:comments>22</slash:comments><comments>http://blogs.msdn.com/theoy/comments/136528.aspx</comments><wfw:commentRss>http://blogs.msdn.com/theoy/commentrss.aspx?PostID=136528</wfw:commentRss><description>&lt;P&gt;&lt;FONT size=2&gt;In the beginning, there was...&lt;BR&gt;&lt;BR&gt;the &lt;STRONG&gt;singleton&lt;/STRONG&gt;.&amp;nbsp; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;Everything's got to start somewhere.&amp;nbsp; Just like there's only one&amp;nbsp;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Lucida Console'"&gt;object&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; type to &amp;#8220;rule them all&amp;#8221;, the singleton represents cases where there's only one.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;A pair of&amp;nbsp;examples&amp;nbsp;are the &lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;TextWriter&lt;/SPAN&gt; instances that represents Standard Out and Standard Error.&amp;nbsp; You only need one instance for each of those, for your &lt;EM&gt;entire program&lt;/EM&gt;.&amp;nbsp; It makes sense for all the code in your program, all the threads, all of ___&lt;U&gt;(insert something here)&lt;/U&gt;_____,&amp;nbsp;to &lt;STRONG&gt;share&lt;/STRONG&gt;.&amp;nbsp; Since there's only&amp;nbsp;one for the entire process, then you might&amp;nbsp;as well represent it that way in your library or codebase.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;Like&amp;nbsp;the&amp;nbsp;proverbial skinning of the cat, there are a bunch of ways&amp;nbsp;to do this.&amp;nbsp; Here's a common&amp;nbsp;one, say our type is Foo.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;
&lt;TABLE class=MsoTableGrid style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BACKGROUND: white; BORDER-LEFT: medium none; WIDTH: 100%; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 5.75pt 5.75pt 5.75pt 5.75pt; mso-yfti-tbllook: 480; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext" cellSpacing=0 cellPadding=0 width="100%" border=1&gt;
&lt;TBODY&gt;
&lt;TR style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"&gt;
&lt;TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.75pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.75pt; PADDING-BOTTOM: 5.75pt; BORDER-LEFT: windowtext 1pt solid; WIDTH: 100%; PADDING-TOP: 5.75pt; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt" vAlign=top width="100%"&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Lucida Console'"&gt;class&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt; Foo {&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// change the default constructor to private&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; Foo() { }&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;static&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;readonly&lt;/SPAN&gt; Foo Only = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; Foo();&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; DoFunctionality();&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=2&gt;The&amp;nbsp;above method is short and simple.&amp;nbsp; Here are the&amp;nbsp;important things to take away:&lt;BR&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;(1) &lt;STRONG&gt;no public constructors&lt;/STRONG&gt;: The point is to share instances, not to let people create their own.&amp;nbsp; The lack of public&amp;nbsp;constructors indicates to developers that this is not your &amp;#8220;run of the&amp;nbsp;mill&amp;#8221; type.&lt;BR&gt;(2)&amp;nbsp;&lt;STRONG&gt;immutable, immutable, immutable&lt;/STRONG&gt;! nine times out of ten&amp;nbsp;you &lt;STRONG&gt;don't&lt;/STRONG&gt;&amp;nbsp;want&amp;nbsp;anything you do to this object to affect other code, threads, etc., in some inadvertent manner.&amp;nbsp; Another word for this is to make your&amp;nbsp;type&amp;nbsp;a &lt;EM&gt;&lt;STRONG&gt;functional&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;type (no new ideas to functional programmers,&amp;nbsp;who are used to dealing with singletons all the time).&amp;nbsp; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;A more common thing that people will find in the .NET&amp;nbsp;libraries is this implementation:&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;/P&gt;
&lt;P&gt;
&lt;TABLE class=MsoTableGrid style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BACKGROUND: white; BORDER-LEFT: medium none; WIDTH: 100%; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 5.75pt 5.75pt 5.75pt 5.75pt; mso-yfti-tbllook: 480; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext" cellSpacing=0 cellPadding=0 width="100%" border=1&gt;
&lt;TBODY&gt;
&lt;TR style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"&gt;
&lt;TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.75pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.75pt; PADDING-BOTTOM: 5.75pt; BORDER-LEFT: windowtext 1pt solid; WIDTH: 100%; PADDING-TOP: 5.75pt; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt" vAlign=top width="100%"&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Lucida Console'"&gt;class&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt; Foo {&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// change the default constructor to private&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; Foo() { }&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;static&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;readonly&lt;/SPAN&gt; Foo sharedOnly = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; Foo();&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;static&lt;/SPAN&gt; Foo Only {&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt; { &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; sharedOnly; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; DoFunctionality();&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;It hides the shared instance of Foo behind a property.&amp;nbsp; Library developers may choose this implementation since allows them to decide later exactly how to return their singleton instance.&amp;nbsp; In fact, in the gang of four design patterns book, the template they outlined is more similar to this, since their examples are in C++.&lt;/P&gt;
&lt;P&gt;Another point to take in&amp;nbsp;mind in regards to hiding your instance behind a property (or a method call) is that the compiler can no longer prove that two different accesses will always return the same instance of the object.&amp;nbsp; It's then up to users of this type to trust the implementation, but then again, it's another&amp;nbsp;possible &amp;#8220;bug&amp;#8221; if your&amp;nbsp;design&amp;nbsp;explicitly wants only ONE instance.&lt;/P&gt;
&lt;P&gt;Yet another common thing to do, if you've decided to abstract out the singleton behind a property is to delay its creation until needed, like so:&lt;/P&gt;
&lt;P&gt;
&lt;TABLE class=MsoTableGrid style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BACKGROUND: white; BORDER-LEFT: medium none; WIDTH: 100%; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 5.75pt 5.75pt 5.75pt 5.75pt; mso-yfti-tbllook: 480; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext" cellSpacing=0 cellPadding=0 width="100%" border=1&gt;
&lt;TBODY&gt;
&lt;TR style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"&gt;
&lt;TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.75pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.75pt; PADDING-BOTTOM: 5.75pt; BORDER-LEFT: windowtext 1pt solid; WIDTH: 100%; PADDING-TOP: 5.75pt; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt" vAlign=top width="100%"&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Lucida Console'"&gt;class&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt; Foo {&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// change the default constructor to private&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; Foo() { }&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;static&lt;/SPAN&gt; Foo sharedOnly = &lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;static&lt;/SPAN&gt; Foo Only {&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt; { &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; (sharedOnly != &lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;) ? sharedOnly :&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN style="mso-tab-count: 4"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;(sharedOnly = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; Foo()); &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; DoFunctionality();&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;Some people may not like the ternary (? :) expression, or the assignment used as an expression, but I think it's perfectly legit in something this simple.&amp;nbsp; What you'll notice changed is the removal of the &lt;SPAN style="COLOR: blue"&gt;&lt;FONT face="Lucida Console"&gt;readonly&lt;/FONT&gt;&lt;/SPAN&gt;&lt;EM&gt;&amp;nbsp;&lt;/EM&gt;attribute, since you're&amp;nbsp;instantiating on demand.&amp;nbsp; Although you're arguably gaining since you don't instantiate objects that you don't need for sure, you're also still opening yourself up for bugs by removing the &lt;SPAN style="COLOR: blue"&gt;&lt;FONT face="Lucida Console"&gt;readonly&lt;/FONT&gt;&lt;/SPAN&gt;&lt;EM&gt;&amp;nbsp;&lt;/EM&gt;attribute (such as accidentally setting that field).&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;If you don't care about getting back the exact same instance, you may wish to statically refer to something similar to the &lt;A href="http://weblogs.asp.net/jaybaz_ms/archive/2004/05/07/128185.aspx"&gt;lazy loader&lt;/A&gt; posted to JayBaz's blog, written by Cyrus, before he got his &lt;A href="http://blogs.msdn.com/cyrusn"&gt;own blog&lt;/A&gt;.&amp;nbsp; But stay tuned to why I think IOptional&amp;lt;T&amp;gt; should be implemented differently.&amp;nbsp; It's been a little over the 48 hours Cyrus promised me to write this all up, but I've since then gotten an extension until morning :-P.&lt;/P&gt;
&lt;P&gt;Others may point out that using either of the examples that employ the use of properties may slow down the program since you're actually executing &lt;EM&gt;code&lt;/EM&gt; whenever you reference a property -- but this is usually trivial overhead, and one can probably assume that the JIT will optimize out the function call.&lt;/P&gt;
&lt;P&gt;I bet you're probably thinking that I'm beating a dead horse, but I wanted to make sure to cover a lot of possible design choices and the pros and cons of each.&amp;nbsp; Next concept in the slate: &lt;STRONG&gt;unions&lt;/STRONG&gt;.&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=136528" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/theoy/archive/tags/OO+Design+101/default.aspx">OO Design 101</category></item><item><title>Coming up: Design Patterns</title><link>http://blogs.msdn.com/theoy/archive/2004/05/20/136483.aspx</link><pubDate>Fri, 21 May 2004 05:07:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:136483</guid><dc:creator>TheoY</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/theoy/comments/136483.aspx</comments><wfw:commentRss>http://blogs.msdn.com/theoy/commentrss.aspx?PostID=136483</wfw:commentRss><description>&lt;P&gt;&lt;FONT size=2&gt;Quick detour (not so much of a detour).&amp;nbsp; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&lt;A href="http://blogs.msdn.com/theoy"&gt;Cyrus&lt;/A&gt; has challenged me to 48 hours in order to expound on how he could've written is IOptional&amp;lt;T&amp;gt; better.&amp;nbsp; Actually, I started to explain some of my suggestions, but now he's imposed this &lt;EM&gt;limit&lt;/EM&gt;, since he's too antsy for me to really finish writing out my entire rationale.&amp;nbsp; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;So instead of writing real code, we're going to talk more about design and theory for a while... but I have a couple of caveats.&lt;BR&gt;&lt;BR&gt;(1) I'm going to assume that you're already familiar with &lt;STRONG&gt;programming in .NET&lt;/STRONG&gt;, and my samples will mostly be in &lt;STRONG&gt;C#&lt;/STRONG&gt; (though they certainly can be ported to other .NET flavors).&lt;BR&gt;(2) I'm also going to assume&amp;nbsp;that&amp;nbsp;you're comfortable with the semantics for &lt;STRONG&gt;single class-inheritance&lt;/STRONG&gt;, as well as &lt;STRONG&gt;virtual methods&lt;/STRONG&gt;.&amp;nbsp; Most of the material won't be directed towards explaining&amp;nbsp;the semantics of the .NET language&amp;nbsp;features, but more along the line of the question,&amp;nbsp;&amp;#8220;&lt;EM&gt;&lt;STRONG&gt;How do I use this the right way?&lt;/STRONG&gt;&amp;#8221;.&lt;BR&gt;&lt;/EM&gt;(3) Virtual methods are prolific throughout abstracted/generalized object oriented programs.&amp;nbsp; These are slower than &amp;#8220;non-virtual&lt;EM&gt;&amp;#8221; &lt;/EM&gt;methods, but they also buy a lot of abstraction and scalability in design.&amp;nbsp; Most people will also agree that the &amp;#8220;performance hit&lt;EM&gt;&amp;#8221;&lt;/EM&gt; is marginal, and the payoff is quite valuable in development time, code complexity, and sustainability.&lt;BR&gt;(4) Most of the examples I'll be writing will not consider thread-safety, which is usually its own can of worms.&amp;nbsp; The main reason is that for most of the upcoming examples, you can workaround thread-safety by giving each thread separate copies (unless they're supposed to share),&amp;nbsp;or you can wrap synchronization logic using decorators.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;With that in mind, let's begin with the &lt;A href="http://blogs.msdn.com/theoy/archive/2004/05/20/136528.aspx"&gt;singleton pattern&lt;/A&gt;.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;Singleton Pattern: &lt;A href="http://blogs.msdn.com/theoy/archive/2004/05/20/136528.aspx"&gt;http://blogs.msdn.com/theoy/archive/2004/05/20/136528.aspx&lt;/A&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=136483" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/theoy/archive/tags/OO+Design+101/default.aspx">OO Design 101</category></item><item><title>Introduction</title><link>http://blogs.msdn.com/theoy/archive/2004/04/11/111122.aspx</link><pubDate>Sun, 11 Apr 2004 08:05:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:111122</guid><dc:creator>TheoY</dc:creator><slash:comments>6</slash:comments><comments>http://blogs.msdn.com/theoy/comments/111122.aspx</comments><wfw:commentRss>http://blogs.msdn.com/theoy/commentrss.aspx?PostID=111122</wfw:commentRss><description>&lt;P&gt;&lt;FONT color=#000000 size=2&gt;Greetings online visitors! &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#000000 size=2&gt;So yes, this is yet another online blog, in fact a [hopefully] technical blog.&amp;nbsp; Fittingly, I should do a bit of a self-introduction to at least establish some history.&amp;nbsp; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;So, to start off &amp;#8220;professionally&amp;#8221;, I'm a&amp;nbsp;developer (a.k.a., SDE, or Software Design Engineer) at Microsoft, based in the Puget Sound area.&amp;nbsp; I'm&amp;nbsp;on the &lt;/FONT&gt;&lt;FONT color=#000000&gt;&lt;A href="http://msdn.microsoft.com/"&gt;Developer Division&lt;/A&gt;&lt;/FONT&gt;&lt;FONT color=#000000&gt; Sustained Engineering team, or DevDiv SE for short.&amp;nbsp; Or DDSE for even shorter.&amp;nbsp; At work, I work a lot on&amp;nbsp;hotfixes for&amp;nbsp;Visual C++ (versions 7.1, 7.0, and yes, even 6.0), which encompasses the editor, as well as &lt;/FONT&gt;&lt;FONT color=#000000&gt;&lt;A href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmfc98/html/mfchm.asp"&gt;MFC&lt;/A&gt;&lt;/FONT&gt;&lt;FONT color=#000000&gt; (Microsoft Foundation Classes), and the &lt;/FONT&gt;&lt;FONT color=#000000&gt;&lt;A href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsintro7/html/vxconATourOfVisualStudio.asp"&gt;Microsoft C Runtime&lt;/A&gt;&lt;/FONT&gt;&lt;FONT color=#000000&gt;.&amp;nbsp; For my team, I also work on internal tools, as well as some &amp;#8220;current&amp;#8221; components of Visual Studio, or other things such as the Microsoft script engine (JScript, VBScript), used for the Windows scripting host, Internet Explorer, and tons of other products.&amp;nbsp; My main languages that I use at work are C++ and C#, and assorted scripting languages as necessary.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;My team also touches the entire rest of Developer Division, which means we're responsible for issuing hotfixes and service packs for the &lt;/FONT&gt;&lt;FONT color=#000000&gt;&lt;A href="http://msdn.microsoft.com/netframework/"&gt;.NET Framework&lt;/A&gt;&lt;/FONT&gt;&lt;FONT color=#000000&gt;, nearly every &lt;/FONT&gt;&lt;FONT color=#000000&gt;&lt;A href="http://msdn.microsoft.com/vstudio/"&gt;Visual Studio&lt;/A&gt;&lt;/FONT&gt;&lt;FONT color=#000000&gt; product, MSDN documentation, etc. -- so I'm one of many &amp;#8220;firefighters&amp;#8221; that try to come to the rescue when a problem is discovered in an already-shipped product in DevDiv.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;Academically, I hold a Bachelors of Science in Computer Science from &lt;/FONT&gt;&lt;FONT color=#000000&gt;&lt;A href="http://www.cs.rice.edu/CS/PLT"&gt;Rice University&lt;/A&gt;&lt;/FONT&gt;&lt;FONT color=#000000&gt; -- where I had a programming languages focus.&amp;nbsp; I really have a passion for object-oriented (OO) design, as well as effective programming languages.&amp;nbsp; This naturally makes me inclined towards interpreters and compilers, but I also enjoy just writing a good OO app.&amp;nbsp;&amp;nbsp;Probably the only other random CS-interest that I have is in network-based programs (i.e. programming for the internet).&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#000000 size=2&gt;Most likely I think my next intention is to eventually begin a slow, but extensive project online with everyone, and being verbose about design decisions, and trying to show maybe some insightful / elegant (or sometimes just nifty) things you can do with the .NET platform.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#000000 size=2&gt;Alright, until next time!&amp;nbsp; Theo, signing out.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#000000 size=1&gt;&lt;EM&gt;This posting is provided "AS IS" with no warranties, and confers no rights.&lt;/EM&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=111122" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/theoy/archive/tags/Personal/default.aspx">Personal</category></item></channel></rss>