<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" media="screen" href="/styles/xslt/rss.xslt"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:c9="http://channel9.msdn.com">
<channel>
	<title>Channel 9 Forums - Tech Off - is &#39;new object().property&#39; or &#39;new object().method()&#39; a good idea?</title>
	<atom:link rel="self" type="application/rss+xml" href="http://channel9.msdn.com/Forums/rss"></atom:link>
	<image>
		<url>http://mschnlnine.vo.llnwd.net/d1/Dev/App_Themes/C9/images/feedimage.png</url>
		<title>Channel 9 Forums - Tech Off - is &#39;new object().property&#39; or &#39;new object().method()&#39; a good idea?</title>
		<link>http://channel9.msdn.com/Forums</link>
	</image>
	<description>Channel 9 keeps you up to date with the latest news and behind the scenes info from Microsoft that developers love to keep up with. From LINQ to SilverLight – Watch videos and hear about all the cool technologies coming and the people behind them.</description>
	<link>http://channel9.msdn.com/Forums</link>
	<language>en</language>
	<pubDate>Wed, 19 Jun 2013 22:20:58 GMT</pubDate>
	<lastBuildDate>Wed, 19 Jun 2013 22:20:58 GMT</lastBuildDate>
	<generator>Rev9</generator>
	<c9:totalResults>41</c9:totalResults>
	<c9:pageCount>-41</c9:pageCount>
	<c9:pageSize>-1</c9:pageSize>
	<item>
		<title>Tech Off - is &#39;new object().property&#39; or &#39;new object().method()&#39; a good idea?</title>
		<description><![CDATA[<p>There is a completely different thread about a slightly tangential topic, but I'm noticing a number of pieces of example code that concerns me.<br /><br />I've done this myself, but how 'safe' is it:<br /><br /><font size="2">Console.WriteLine(new String(&quot;Bob&quot;).Length);<br /><br /></font><font size="2">The part that concerns me is the accessing of the function 'Length' when you don't really know that the new String has actually been created.<br /><br />The other side of the coin, however, is that you could end up with twice as many lines of code if you check every single variable before using it.<br /><br />What do you do?</p>
</font>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/259414#259414</link>
		<pubDate>Mon, 03 Dec 2007 16:09:21 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/259414#259414</guid>
		<dc:creator>ScanIAm</dc:creator>
		<slash:comments>41</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/ScanIAm/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - is &#39;new object().property&#39; or &#39;new object().method()&#39; a good idea?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">ScanIAm wrote:</div>
<div class="quoteBody">&#65279;
<p>There is a completely different thread about a slightly tangential topic, but I'm noticing a number of pieces of example code that concerns me.<br /><br />I've done this myself, but how 'safe' is it:<br /><br /><font size="2">Console.WriteLine(new String(&quot;Bob&quot;).Length);<br /><br /></font><font size="2">The part that concerns me is the accessing of the function 'Length' when you don't really know that the new String has actually been created.<br /><br />The other side of the coin, however, is that you could end up with twice as many lines of code if you check every single variable before using it.<br /><br />What do you do?</p>
</font></div>
</blockquote>
<br /><br />First, your example is bad:<br /><br />Console.WriteLine(&quot;Bob&quot;.Length);<br /><br />However, the idea is there, so I'll address it.&nbsp; The new String will either be created, thus no problem, or an exception will be thrown and so Length won't be called, so also no problem.&nbsp; The only problems that exist here exist whether or not you &quot;chain&quot; the
 calls to the constructor.<br /><br />Check the variable before using it?&nbsp; Like I said, either it worked, and so there's no reason to check, or it threw an exception, so there's no reason to check.&nbsp; I guess I don't get what you think the problem is?</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/00469d81fc8f4cf795189dfa00865721#00469d81fc8f4cf795189dfa00865721</link>
		<pubDate>Mon, 03 Dec 2007 16:43:00 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/00469d81fc8f4cf795189dfa00865721#00469d81fc8f4cf795189dfa00865721</guid>
		<dc:creator>William Kempf</dc:creator>
		<slash:comments>41</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/wkempf/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - is &#39;new object().property&#39; or &#39;new object().method()&#39; a good idea?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">ScanIAm wrote:</div>
<div class="quoteBody">&#65279;
<p>There is a completely different thread about a slightly tangential topic, but I'm noticing a number of pieces of example code that concerns me.<br /><br />I've done this myself, but how 'safe' is it:<br /><br /><font size="2">Console.WriteLine(new String(&quot;Bob&quot;).Length);<br /><br /></font><font size="2">The part that concerns me is the accessing of the function 'Length' when you don't really know that the new String has actually been created.<br /><br />The other side of the coin, however, is that you could end up with twice as many lines of code if you check every single variable before using it.<br /><br />What do you do?</font></p>
</div>
</blockquote>
<br /><br />In an unsafe language like C that is absolutely correct:<br /><br />#include &lt;string.h&gt;<br /><br />int main(){<br />&nbsp; int len;<br />&nbsp; string b;<br /><br />&nbsp; b = (string)malloc(sizeof(char) * 3);<br />&nbsp; strcpy(b, &quot;Bob\0&quot;, 3);<br />&nbsp; len = strlen(b);<br />}<br /><br /><br />Should have checks in it:<br /><br /><br />int main(){<br />&nbsp; int len;<br />&nbsp; string b;<br /><br />&nbsp; b = (string)malloc(sizeof(char) * 3);<br /><font color="#ff0000">&nbsp; assert(b != NULL);</font><br />&nbsp; strcpy(b, &quot;Bob\0&quot;, 3);<br />&nbsp; len = strlen(b);<br />}<br /><br />In case you run your system down to the point where it can't allocate 3 bytes for you (heaven forbid).<br /><br />In a language like C#, however, new is a memory safe operation, since if the internal malloc fails a new OutOfMemoryException() is thrown at the il line where the newobj instruction is.<br /><br />There is no <i>T</i> such that <br />new <i>T</i>( args ...) === null<br /><br />however, the line new <i>T</i>(args ... ) can throw an OutOfMemoryException if there is not enough system memory to allocate T on the stack.<br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/940304c9e1064aaaba1c9dfa008657a1#940304c9e1064aaaba1c9dfa008657a1</link>
		<pubDate>Mon, 03 Dec 2007 17:05:52 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/940304c9e1064aaaba1c9dfa008657a1#940304c9e1064aaaba1c9dfa008657a1</guid>
		<dc:creator>evildictaitor</dc:creator>
		<slash:comments>41</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/evildictaitor/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - is &#39;new object().property&#39; or &#39;new object().method()&#39; a good idea?</title>
		<description><![CDATA[<p>I think the whole topic is splitting hairs in managed code. C or C&#43;&#43; I can see worrying. When you hard coding the string like you suggest&nbsp;I see no problem not testing for IsEmptyOrNull&nbsp;as you will always get the same result. In random input scenarios like
 reading in from file, form etc I would always test for invalid input before you commit it to anything non trivial.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/7599ad10e99f478d95ae9dfa0086581b#7599ad10e99f478d95ae9dfa0086581b</link>
		<pubDate>Mon, 03 Dec 2007 17:37:33 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/7599ad10e99f478d95ae9dfa0086581b#7599ad10e99f478d95ae9dfa0086581b</guid>
		<dc:creator>odujosh</dc:creator>
		<slash:comments>41</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/odujosh/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - is &#39;new object().property&#39; or &#39;new object().method()&#39; a good idea?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">ScanIAm wrote:</div>
<div class="quoteBody">&#65279;<br />I've done this myself, but how 'safe' is it:<br /><br /><font size="2">Console.WriteLine(new String(&quot;Bob&quot;).Length);<br /><br /></font><font size="2">The part that concerns me is the accessing of the function 'Length' when you don't really know that the new String has actually been created.<br /></font></div>
</blockquote>
<br /><br />You absolutely know that the new String has been created before Length is called. An exception will be thrown if the String could not be created.<br /><br /><font color="#a52a2a"><font color="#ffa500">[Edge case ahead.]</font><br /></font><br />Now, in the case of<br /><br /><font color="#0000ff" size="2">
<p>&nbsp;&nbsp;&nbsp; <font face="Courier New">new</font></font><font face="Courier New"><font size="2">
</font><font color="#2b91af" size="2">MyObject</font><font size="2">().LongRunningMethod();</p>
</font></font>the instance of <font face="Courier New" color="#2b91af" size="2">MyObject</font>
<a href="http://www.codeneverwritten.com/2007/12/where-did-my-object-go-part-1.html">
may be garbage collected</a> before <font face="Courier New" size="2">LongRunningMethod</font> returns. This usually doesn't cause a problem, but it can; to cause a problem&nbsp;usually involves a questionable design decision (e.g., a disposed
<font face="Courier New" color="#2b91af" size="2">MyObject</font> cleans up a field, and this
<em>happens</em> to occur&nbsp;after <font face="Courier New" size="2">LongRunningMethod</font>'s last reference to your
<font face="Courier New" color="#2b91af" size="2">MyObject</font> instance but before using a locally stored&nbsp;reference to that field). I can make it happen but I don't expect to see it in the wild.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/c977ff3ce7e245b5b9d59dfa0086589d#c977ff3ce7e245b5b9d59dfa0086589d</link>
		<pubDate>Mon, 03 Dec 2007 20:21:18 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/c977ff3ce7e245b5b9d59dfa0086589d#c977ff3ce7e245b5b9d59dfa0086589d</guid>
		<dc:creator>Curt Nichols</dc:creator>
		<slash:comments>41</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Curt Nichols/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - is &#39;new object().property&#39; or &#39;new object().method()&#39; a good idea?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">Curt Nichols wrote:</div>
<div class="quoteBody">&#65279;
<blockquote>
<table class="quoteTable">
<tbody>
<tr>
<td valign="top" width="10"><img src="/Themes/AlmostGlass/images/icon-quote.gif"></td>
<td class="txt3"><strong>ScanIAm wrote:</strong>
<hr size="1">
<i>&#65279;<br />I've done this myself, but how 'safe' is it:<br /><br /><font size="2">Console.WriteLine(new String(&quot;Bob&quot;).Length);<br /><br /></font><font size="2">The part that concerns me is the accessing of the function 'Length' when you don't really know that the new String has actually been created.<br /></font></i></td>
</tr>
</tbody>
</table>
</blockquote>
<br /><br />You absolutely know that the new String has been created before Length is called. An exception will be thrown if the String could not be created.<br /><br /><font color="#a52a2a"><font color="#ffa500">[Edge case ahead.]</font><br /></font><br />Now, in the case of<br /><br /><font color="#0000ff" size="2"></font>
<p><font color="#0000ff" size="2">&nbsp;&nbsp;&nbsp; <font face="Courier New">new</font></font><font face="Courier New"><font size="2">
</font><font color="#2b91af" size="2">MyObject</font><font size="2">().LongRunningMethod();</font></font></p>
the instance of <font color="#2b91af" face="Courier New" size="2">MyObject</font>
<a href="http://www.codeneverwritten.com/2007/12/where-did-my-object-go-part-1.html">
may be garbage collected</a> before <font face="Courier New" size="2">LongRunningMethod</font> returns. This usually doesn't cause a problem, but it can; to cause a problem&nbsp;usually involves a questionable design decision (e.g., a disposed
<font color="#2b91af" face="Courier New" size="2">MyObject</font> cleans up a field, and this
<em>happens</em> to occur&nbsp;after <font face="Courier New" size="2">LongRunningMethod</font>'s last reference to your
<font color="#2b91af" face="Courier New" size="2">MyObject</font> instance but before using a locally stored&nbsp;reference to that field). I can make it happen but I don't expect to see it in the wild.</div>
</blockquote>
<br /><br />This is interesting, and would be a bug in the CLR.<br /><br />You won't be able to test for it either since<br /><br />1:&nbsp; MyObject o = new MyObject();<br />2:&nbsp; if(null == o)<br />3: &nbsp;&nbsp; throw new Exception();<br />4:&nbsp; var result = o.LongRunningMethod();<br /><br />If what you say is correct then lines 2 and 3 are superflouous since o could be garbage collected between 2,3 and 4.<br /><br />To protect against it you could do <br /><br />MyObject o = new MyObject();<br />var result = o.LongRunningMethod();<br />GC.KeepAlive(o);<br /><br />But in fairness this is a bug that should be fixed by Microsoft rather than coded around, and you should write an bugreport if you find in your code that this is happening.<br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/f8a447442b634e16923b9dfa0086590b#f8a447442b634e16923b9dfa0086590b</link>
		<pubDate>Mon, 03 Dec 2007 20:48:55 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/f8a447442b634e16923b9dfa0086590b#f8a447442b634e16923b9dfa0086590b</guid>
		<dc:creator>evildictaitor</dc:creator>
		<slash:comments>41</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/evildictaitor/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - is &#39;new object().property&#39; or &#39;new object().method()&#39; a good idea?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">wkempf wrote:</div>
<div class="quoteBody">&#65279;
<blockquote>
<table class="quoteTable">
<tbody>
<tr>
<td valign="top" width="10"><img src="/Themes/AlmostGlass/images/icon-quote.gif"></td>
<td class="txt3"><strong>ScanIAm wrote:</strong>
<hr size="1">
<i>&#65279;
<p>There is a completely different thread about a slightly tangential topic, but I'm noticing a number of pieces of example code that concerns me.<br /><br />I've done this myself, but how 'safe' is it:<br /><br /><font size="2">Console.WriteLine(new String(&quot;Bob&quot;).Length);<br /><br /></font><font size="2">The part that concerns me is the accessing of the function 'Length' when you don't really know that the new String has actually been created.<br /><br />The other side of the coin, however, is that you could end up with twice as many lines of code if you check every single variable before using it.<br /><br />What do you do?</p>
</font></i></td>
</tr>
</tbody>
</table>
</blockquote>
<br /><br />First, your example is bad:<br /><br />Console.WriteLine(&quot;Bob&quot;.Length);<br /><br />However, the idea is there, so I'll address it.&nbsp; The new String will either be created, thus no problem, or an exception will be thrown and so Length won't be called, so also no problem.&nbsp; The only problems that exist here exist whether or not you &quot;chain&quot; the
 calls to the constructor.<br /><br />Check the variable before using it?&nbsp; Like I said, either it worked, and so there's no reason to check, or it threw an exception, so there's no reason to check.&nbsp; I guess I don't get what you think the problem is?</div>
</blockquote>
<br /><br />Yep, that's what I get for not actually compiling the code and testing it, but it was meant as an example.<br /><br />I've seen this used, more often, when adding ListItem to a radiobutton/combobox/dropdownlist.&nbsp;
<br /><br />I guess, for me, the fear of using this construct comes from C/C&#43;&#43; training.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/e2f0ac237ba54aa0bb439dfa0086596d#e2f0ac237ba54aa0bb439dfa0086596d</link>
		<pubDate>Mon, 03 Dec 2007 21:56:40 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/e2f0ac237ba54aa0bb439dfa0086596d#e2f0ac237ba54aa0bb439dfa0086596d</guid>
		<dc:creator>ScanIAm</dc:creator>
		<slash:comments>41</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/ScanIAm/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - is &#39;new object().property&#39; or &#39;new object().method()&#39; a good idea?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">evildictaitor wrote:</div>
<div class="quoteBody">&#65279;<br /><br />Should have checks in it:<br /><br /><br />int main(){<br />&nbsp; int len;<br />&nbsp; string b;<br /><br />&nbsp; b = (string)malloc(sizeof(char) * 3);<br /><font color="#ff0000">&nbsp; assert(b != NULL);</font><br />&nbsp; strcpy(b, &quot;Bob\0&quot;, 3);<br />&nbsp; len = strlen(b);<br />}<br /><br /></div>
</blockquote>
<br /><br />assert really doesn't count as a check, since it is only functional during debugging sessions. For runtime checks you really should use a proper if else construct.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/d61b9d8ce36340f6a33c9dfa008659e2#d61b9d8ce36340f6a33c9dfa008659e2</link>
		<pubDate>Mon, 03 Dec 2007 22:26:17 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/d61b9d8ce36340f6a33c9dfa008659e2#d61b9d8ce36340f6a33c9dfa008659e2</guid>
		<dc:creator>AndyC</dc:creator>
		<slash:comments>41</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/AndyC/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - is &#39;new object().property&#39; or &#39;new object().method()&#39; a good idea?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">AndyC wrote:</div>
<div class="quoteBody">&#65279;
<blockquote>
<table class="quoteTable">
<tbody>
<tr>
<td valign="top" width="10"><img src="/Themes/AlmostGlass/images/icon-quote.gif"></td>
<td class="txt3"><strong>evildictaitor wrote:</strong>
<hr size="1">
<i>&#65279;<br /><br />Should have checks in it:<br /><br /><br />int main(){<br />&nbsp; int len;<br />&nbsp; string b;<br /><br />&nbsp; b = (string)malloc(sizeof(char) * 3);<br /><font color="#ff0000">&nbsp; assert(b != NULL);</font><br />&nbsp; strcpy(b, &quot;Bob\0&quot;, 3);<br />&nbsp; len = strlen(b);<br />}<br /><br /></i></td>
</tr>
</tbody>
</table>
</blockquote>
<br /><br />assert really doesn't count as a check, since it is only functional during debugging sessions. For runtime checks you really should use a proper if else construct.</div>
</blockquote>
<br /><br />Well if we're being fussy we can go into propagating error results or implementing the C Exception library, but I was just trying to get my point across, not write release code <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-4.gif' alt='Tongue Out' /><br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/38c571f22f954c4999e39dfa00865a3e#38c571f22f954c4999e39dfa00865a3e</link>
		<pubDate>Mon, 03 Dec 2007 22:53:17 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/38c571f22f954c4999e39dfa00865a3e#38c571f22f954c4999e39dfa00865a3e</guid>
		<dc:creator>evildictaitor</dc:creator>
		<slash:comments>41</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/evildictaitor/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - is &#39;new object().property&#39; or &#39;new object().method()&#39; a good idea?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">Curt Nichols wrote:</div>
<div class="quoteBody">&#65279;
<blockquote>
<table class="quoteTable">
<tbody>
<tr>
<td valign="top" width="10"><img src="/Themes/AlmostGlass/images/icon-quote.gif"></td>
<td class="txt3"><strong>ScanIAm wrote:</strong>
<hr size="1">
<i>&#65279;<br />I've done this myself, but how 'safe' is it:<br /><br /><font size="2">Console.WriteLine(new String(&quot;Bob&quot;).Length);<br /><br /></font><font size="2">The part that concerns me is the accessing of the function 'Length' when you don't really know that the new String has actually been created.<br /></font></i></td>
</tr>
</tbody>
</table>
</blockquote>
<br /><br />You absolutely know that the new String has been created before Length is called. An exception will be thrown if the String could not be created.<br /><br /><font color="#a52a2a"><font color="#ffa500">[Edge case ahead.]</font><br /></font><br />Now, in the case of<br /><br /><font color="#0000ff" size="2">
<p>&nbsp;&nbsp;&nbsp; <font face="Courier New">new</font></font><font face="Courier New"><font size="2">
</font><font color="#2b91af" size="2">MyObject</font><font size="2">().LongRunningMethod();</p>
</font></font>the instance of <font face="Courier New" color="#2b91af" size="2">MyObject</font>
<a href="http://www.codeneverwritten.com/2007/12/where-did-my-object-go-part-1.html">
may be garbage collected</a> before <font face="Courier New" size="2">LongRunningMethod</font> returns. This usually doesn't cause a problem, but it can; to cause a problem&nbsp;usually involves a questionable design decision (e.g., a disposed
<font face="Courier New" color="#2b91af" size="2">MyObject</font> cleans up a field, and this
<em>happens</em> to occur&nbsp;after <font face="Courier New" size="2">LongRunningMethod</font>'s last reference to your
<font face="Courier New" color="#2b91af" size="2">MyObject</font> instance but before using a locally stored&nbsp;reference to that field). I can make it happen but I don't expect to see it in the wild.</div>
</blockquote>
<br /><br />The MyObject instance won't be collected by the GC if you are accessing any fields that held by that instance... otherwise - as said - it would be a heavy CLR (GC) bug!</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/dd10bc2ba6864a79881c9dfa00865abd#dd10bc2ba6864a79881c9dfa00865abd</link>
		<pubDate>Mon, 03 Dec 2007 22:59:22 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/dd10bc2ba6864a79881c9dfa00865abd#dd10bc2ba6864a79881c9dfa00865abd</guid>
		<dc:creator>Christian Liensberger</dc:creator>
		<slash:comments>41</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/littleguru/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - is &#39;new object().property&#39; or &#39;new object().method()&#39; a good idea?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">ScanIAm wrote:</div>
<div class="quoteBody">&#65279;<font size="2">Console.WriteLine(new String(&quot;Bob&quot;).Length);<br /><br /></font><font size="2">The part that concerns me is the accessing of the function 'Length' when you don't really know that the new String has actually been created.</font></div>
</blockquote>
<br />Ignoring that String is&nbsp;a bad example because you can do &quot;Bob&quot;.Length (as was mentioned), I still don't see what you're getting at.<br /><br />What is it you want to check? Any error conditions that cause the object not to be created would throw an exception.<br /><br />Code like what evildictaitor wrote:<br />MyObject o = new MyObject();<br />if( o == null )<br />&nbsp;&nbsp;&nbsp;throw new Exception();<br /><br />That's completely pointless. O can <strong>never</strong> be null after a &quot;new&quot;, since if the object couldn't be created an exception would be thrown (e.g. an OutOfMemoryException).</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/d6bc92504b594b5794c59dfa00865b32#d6bc92504b594b5794c59dfa00865b32</link>
		<pubDate>Mon, 03 Dec 2007 23:51:53 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/d6bc92504b594b5794c59dfa00865b32#d6bc92504b594b5794c59dfa00865b32</guid>
		<dc:creator>Sven Groot</dc:creator>
		<slash:comments>41</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Sven Groot/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - is &#39;new object().property&#39; or &#39;new object().method()&#39; a good idea?</title>
		<description><![CDATA[<p>I ~think what your asking is if that var gets collected correctly as it is an internal assignment.&nbsp; That is interesting as I recall a c# ng thread circa 2.0 that someone showed that is was never collected even after some GCs.&nbsp; I personally did not test
 or repro the issue, but IIRC, others could repo the issue.&nbsp; Me thinks it was fixed, but not sure.&nbsp; Save that issue, I don't see a problem other then it would be easier to debug if ctor and assignment was on a line by itself and maybe more clear.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/7b3d489082a6422892ca9dfa00865baa#7b3d489082a6422892ca9dfa00865baa</link>
		<pubDate>Tue, 04 Dec 2007 02:28:22 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/7b3d489082a6422892ca9dfa00865baa#7b3d489082a6422892ca9dfa00865baa</guid>
		<dc:creator>William Stacey</dc:creator>
		<slash:comments>41</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/staceyw/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - is &#39;new object().property&#39; or &#39;new object().method()&#39; a good idea?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">littleguru wrote:</div>
<div class="quoteBody">&#65279;<br /><br />The MyObject instance won't be collected by the GC if you are accessing any fields that held by that instance... otherwise - as said - it would be a heavy CLR (GC) bug!</div>
</blockquote>
<br /><br />Just to shed a little light on the situation the typical example of this is using IntPtr's and the Dispose pattern.&nbsp; Such as:<br /><br />class MyDisposable : IDisposable {<br />&nbsp;&nbsp;&nbsp; private IntPtr _foo;<br />&nbsp;&nbsp;&nbsp; public void DoIt() {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SomePInvokeOperation(_foo);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;~MyDisposable() {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Dispose();<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp; public void Dispose() {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CloseMyHandle(_foo);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GC.SuppressFinalization(this);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br />Now you do: new MyDisposable().DoIt();&nbsp; The IntPtr is read and right after that read there are no longer any references to the MyDisposable() instance.&nbsp; Before SomePInvokeOperation can run the GC kicks in and&nbsp;collects the MyDisposable class.&nbsp; Next the finalizer
 thread runs which runs the finalizer&nbsp;which closes the native resource.&nbsp; Finally your SomePInvokeOperation runs and is operating on a _foo that is no longer valid.<br /><br />The worst case scenario here is that you can use this for a handle recycling attack which violates security.&nbsp; If you're lucky the app is just going to crash.&nbsp; Anyway, the way to fix this is to put a GC.KeepAlive(this); in DoIt() so that the object survives
 the lifetime of the call.&nbsp; But it's really only a problem when you're interacting with native resources which the GC doesn't understand and keep alive its self.&nbsp; So still not a bug, but a good thing to know about if you're doing any interop programming.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/42fa4b4480bf4ac0a7db9dfa00865c30#42fa4b4480bf4ac0a7db9dfa00865c30</link>
		<pubDate>Tue, 04 Dec 2007 03:28:33 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/42fa4b4480bf4ac0a7db9dfa00865c30#42fa4b4480bf4ac0a7db9dfa00865c30</guid>
		<dc:creator>DinoViehland</dc:creator>
		<slash:comments>41</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/DinoViehland/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - is &#39;new object().property&#39; or &#39;new object().method()&#39; a good idea?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">Curt Nichols wrote:</div>
<div class="quoteBody"><br />...&#65279;<br /><br /><font color="#a52a2a"><font color="#ffa500">[Edge case ahead.]</font><br /></font><br />Now, in the case of<br /><br /><font color="#0000ff" size="2"></font>
<p><font color="#0000ff" size="2">&nbsp;&nbsp;&nbsp; <font face="Courier New">new</font></font><font face="Courier New"><font size="2">
</font><font color="#2b91af" size="2">MyObject</font><font size="2">().LongRunningMethod();</font></font></p>
the instance of <font color="#2b91af" face="Courier New" size="2">MyObject</font>
<a href="http://www.codeneverwritten.com/2007/12/where-did-my-object-go-part-1.html">
may be garbage collected</a> before <font face="Courier New" size="2">LongRunningMethod</font> returns. This usually doesn't cause a problem, but it can; to cause a problem&nbsp;usually involves a questionable design decision (e.g., a disposed
<font color="#2b91af" face="Courier New" size="2">MyObject</font> cleans up a field, and this
<em>happens</em> to occur&nbsp;after <font face="Courier New" size="2">LongRunningMethod</font>'s last reference to your
<font color="#2b91af" face="Courier New" size="2">MyObject</font> instance but before using a locally stored&nbsp;reference to that field). I can make it happen but I don't expect to see it in the wild.</div>
</blockquote>
<br /><br />This is not a problem and this is why:<br /><br />1) if <font face="Courier New"><font size="2">LongRunningMethod() acceses fields on MyObject instance the &quot;this&quot; parameter is passed on the stack to the method meaning you have a rooted reference to the object instance, the method call practicaly is like this<br /><br />newobj MyObject //Returns a reference in the stack <br />call </font></font><font face="Courier New"><font size="2">LongRunningMethod<br /><br />so when the LongRunningMethod is called there is a reference in the stack pointing at the
</font></font><font face="Courier New"><font color="#2b91af" size="2">MyObject</font><font size="2"> instance. Also because
</font></font><font face="Courier New"><font size="2">LongRunningMethod acceses fields of the object it keeps a referente to the object instace in it's own stack frame and the object won't be garbage colected.<br /><br />2) </font></font><font face="Courier New"><font size="2">LongRunningMethod() doesn't access any fields on MyObject instance so that means even if the object is garbage colected (because now the jit can optimize the method to eliminate the reference from the
 stack) the method will never try to dereference a null object (the this pointer) so won't get a NullReference exception.<br /><br />To test it you can even try to call with reflection a instance method that doesn't access any fields passing a null value and it will work.<br /><br />NullReference is only thown when you try to dereference a null pointer and not by calling a method (if that method doesn't try to dereference a null pointer the exception will never be thrown)<br /><br /></font></font></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/dfc684069db341f78f8a9dfa00865cb1#dfc684069db341f78f8a9dfa00865cb1</link>
		<pubDate>Tue, 04 Dec 2007 11:19:41 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/dfc684069db341f78f8a9dfa00865cb1#dfc684069db341f78f8a9dfa00865cb1</guid>
		<dc:creator>Pop Catalin</dc:creator>
		<slash:comments>41</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Pop Catalin Sever/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - is &#39;new object().property&#39; or &#39;new object().method()&#39; a good idea?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">Sven Groot wrote:</div>
<div class="quoteBody">&#65279;
<blockquote>
<table class="quoteTable">
<tbody>
<tr>
<td valign="top" width="10"><img src="/Themes/AlmostGlass/images/icon-quote.gif"></td>
<td class="txt3"><strong>ScanIAm wrote:</strong>
<hr size="1">
<i>&#65279;<font size="2">Console.WriteLine(new String(&quot;Bob&quot;).Length);<br /><br /></font><font size="2">The part that concerns me is the accessing of the function 'Length' when you don't really know that the new String has actually been created.</font></i></td>
</tr>
</tbody>
</table>
</blockquote>
<br />Ignoring that String is&nbsp;a bad example because you can do &quot;Bob&quot;.Length (as was mentioned), I still don't see what you're getting at.<br /><br />What is it you want to check? Any error conditions that cause the object not to be created would throw an exception.<br /><br />Code like what evildictaitor wrote:<br />MyObject o = new MyObject();<br />if( o == null )<br />&nbsp;&nbsp;&nbsp;throw new Exception();<br /><br />That's completely pointless. O can <strong>never</strong> be null after a &quot;new&quot;, since if the object couldn't be created an exception would be thrown (e.g. an OutOfMemoryException).</div>
</blockquote>
<br /><br />Exactly, and I'm fine with that, now, but it doesn't 'feel' right.&nbsp; That's my own cross to bear <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif' alt='Smiley' /><br /><br />string s = &quot;bob&quot;;<br />if(s!=null)<br />&nbsp;&nbsp;&nbsp;Console.WriteLine(bob.Length);<br /><br />just seems safer.<br /><br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/a9157686e49841a8a4f49dfa00865d0b#a9157686e49841a8a4f49dfa00865d0b</link>
		<pubDate>Tue, 04 Dec 2007 18:02:39 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/a9157686e49841a8a4f49dfa00865d0b#a9157686e49841a8a4f49dfa00865d0b</guid>
		<dc:creator>ScanIAm</dc:creator>
		<slash:comments>41</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/ScanIAm/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - is &#39;new object().property&#39; or &#39;new object().method()&#39; a good idea?</title>
		<description><![CDATA[<p>Well, you do that.. <br /><br />The concept behind most things in .NET is; the operation either worked, or it didn't (and caused an exception)..<br /><br />All these pointless null checks are just chipping away at your performance slowly.. your code will be utterly confusing for anyone else who has to take it over..<br /><br />I'd put the action to work, and work on getting over mentally, because carrying on doing that is bad practice for a .NET app..
<br /><br /><img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-5.gif' alt='Wink' /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/8c2c0dc0bf6d434aa4859dfa00865d7d#8c2c0dc0bf6d434aa4859dfa00865d7d</link>
		<pubDate>Tue, 04 Dec 2007 18:11:40 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/8c2c0dc0bf6d434aa4859dfa00865d7d#8c2c0dc0bf6d434aa4859dfa00865d7d</guid>
		<dc:creator>stevo_</dc:creator>
		<slash:comments>41</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/stevo_/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - is &#39;new object().property&#39; or &#39;new object().method()&#39; a good idea?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">ScanIAm wrote:</div>
<div class="quoteBody">&#65279;
<blockquote>
<table class="quoteTable">
<tbody>
<tr>
<td valign="top" width="10"><img src="/Themes/AlmostGlass/images/icon-quote.gif"></td>
<td class="txt3"><strong>Sven Groot wrote:</strong>
<hr size="1">
<i>&#65279;
<blockquote>
<table class="quoteTable">
<tbody>
<tr>
<td valign="top" width="10"><img src="/Themes/AlmostGlass/images/icon-quote.gif"></td>
<td class="txt3"><strong>ScanIAm wrote:</strong>
<hr size="1">
<i>&#65279;<font size="2">Console.WriteLine(new String(&quot;Bob&quot;).Length);<br /><br /></font><font size="2">The part that concerns me is the accessing of the function 'Length' when you don't really know that the new String has actually been created.</font></i></td>
</tr>
</tbody>
</table>
</blockquote>
<br />Ignoring that String is&nbsp;a bad example because you can do &quot;Bob&quot;.Length (as was mentioned), I still don't see what you're getting at.<br /><br />What is it you want to check? Any error conditions that cause the object not to be created would throw an exception.<br /><br />Code like what evildictaitor wrote:<br />MyObject o = new MyObject();<br />if( o == null )<br />&nbsp;&nbsp;&nbsp;throw new Exception();<br /><br />That's completely pointless. O can <strong>never</strong> be null after a &quot;new&quot;, since if the object couldn't be created an exception would be thrown (e.g. an OutOfMemoryException).</i></td>
</tr>
</tbody>
</table>
</blockquote>
<br /><br />Exactly, and I'm fine with that, now, but it doesn't 'feel' right.&nbsp; That's my own cross to bear <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif' alt='Smiley' /><br /><br />string s = &quot;bob&quot;;<br />if(s!=null)<br />&nbsp;&nbsp;&nbsp;Console.WriteLine(bob.Length);<br /><br />just seems safer.<br /><br /></div>
</blockquote>
<br /><br />Feeling are important.&nbsp; You should do what feels right.&nbsp; However &quot;abc&quot;.length will *never be null, unless there is some very strange memory issue or hardware failure - in which case, you have bigger issues to deal with.&nbsp; Happy coding <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif' alt='Smiley' /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/8f5173c58383402b989d9dfa00865ddd#8f5173c58383402b989d9dfa00865ddd</link>
		<pubDate>Tue, 04 Dec 2007 18:12:00 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/8f5173c58383402b989d9dfa00865ddd#8f5173c58383402b989d9dfa00865ddd</guid>
		<dc:creator>William Stacey</dc:creator>
		<slash:comments>41</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/staceyw/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - is &#39;new object().property&#39; or &#39;new object().method()&#39; a good idea?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">ScanIAm wrote:</div>
<div class="quoteBody"><br /><br />Exactly, and I'm fine with that, now, but it doesn't 'feel' right.&nbsp; That's my own cross to bear <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif' alt='Smiley' /><br /><br />string s = &quot;bob&quot;;<br />if(s!=null)<br />&nbsp;&nbsp;&nbsp;Console.WriteLine(bob.Length);<br /><br />just seems safer.<br /><br /></div>
</blockquote>
<br /><br />It may seem to you safer, but if you dig deeper into the innner workings of .Net (reading books, blogs, articles etc)&nbsp; it won't seem safer anymore it will seem redundant and also less performant.<br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/1a599eead3b043baacea9dfa00865e35#1a599eead3b043baacea9dfa00865e35</link>
		<pubDate>Tue, 04 Dec 2007 18:19:50 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/1a599eead3b043baacea9dfa00865e35#1a599eead3b043baacea9dfa00865e35</guid>
		<dc:creator>Pop Catalin</dc:creator>
		<slash:comments>41</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Pop Catalin Sever/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - is &#39;new object().property&#39; or &#39;new object().method()&#39; a good idea?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">ScanIAm wrote:</div>
<div class="quoteBody">&#65279;Console.WriteLine(new String(&quot;Bob&quot;).Length);<br /><p><font size="2"><br /></font><font size="2">The part that concerns me is the accessing of the function 'Length' when you don't really know that the new String has actually been created.</font></p>
</div>
</blockquote>
<p></p>
Of course you know that the new String has been created.&nbsp; why would you not?&nbsp; that's exactly what you are telling the compiler to do. consider:<br /><br /><font face="Courier New">namespace ConsoleApplication1<br />{<br />&nbsp;&nbsp;&nbsp; class Program<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; static void Main(string[] args)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.Console.WriteLine(new System.String('c', 10).Length);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />}</font><br /><br /><br />&nbsp;here you are telling the runtime to create a new object of type String by calling the constructor with provided parameters, get the Length property, and pass a copy of it to the Console.WriteLine function.&nbsp; from there it doesn't matter what happens to the
 String object because it is no longer needed; the WriteLine function has it's own copy (because it's a value type) of what we wanted, so no worries.<br /><br />am i right, guys?<br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/6e3c780ceace48f2b4129dfa00865eb6#6e3c780ceace48f2b4129dfa00865eb6</link>
		<pubDate>Wed, 05 Dec 2007 18:22:00 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/6e3c780ceace48f2b4129dfa00865eb6#6e3c780ceace48f2b4129dfa00865eb6</guid>
		<dc:creator>A1C Stephen Collins</dc:creator>
		<slash:comments>41</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/vbrunner__/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - is &#39;new object().property&#39; or &#39;new object().method()&#39; a good idea?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">ScanIAm wrote:</div>
<div class="quoteBody">&#65279;
<blockquote>Exactly, and I'm fine with that, now, but it doesn't 'feel' right.&nbsp; That's my own cross to bear <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif' alt='Smiley' /><br /><br />string s = &quot;bob&quot;;<br />if(s!=null)<br />&nbsp;&nbsp;&nbsp;Console.WriteLine(bob.Length);<br /><br />just seems safer.<br /><br /></blockquote>
</div>
</blockquote>
<br /><br /><br />Sorry, that's just not making sense; maybe you need to come up with a better example, but I can't see it.&nbsp; s can never be null here ... even if it was you'd sure as hell WANT an exception to be thrown, because it's exceptional ... you don't want to hide this
 kind of exception.
<blockquote></blockquote></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/b6ed7ef836e54f569d0e9dfa00865f2d#b6ed7ef836e54f569d0e9dfa00865f2d</link>
		<pubDate>Wed, 05 Dec 2007 18:34:48 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/b6ed7ef836e54f569d0e9dfa00865f2d#b6ed7ef836e54f569d0e9dfa00865f2d</guid>
		<dc:creator>Richard Anthony Hein</dc:creator>
		<slash:comments>41</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Richard.Hein/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - is &#39;new object().property&#39; or &#39;new object().method()&#39; a good idea?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">Richard.Hein wrote:</div>
<div class="quoteBody">&#65279;
<blockquote>
<table class="quoteTable">
<tbody>
<tr>
<td valign="top" width="10"><img src="/Themes/AlmostGlass/images/icon-quote.gif"></td>
<td class="txt3"><strong>ScanIAm wrote:</strong>
<hr size="1">
<i>&#65279;
<blockquote>Exactly, and I'm fine with that, now, but it doesn't 'feel' right.&nbsp; That's my own cross to bear <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif' alt='Smiley' /><br /><br />string s = &quot;bob&quot;;<br />if(s!=null)<br />&nbsp;&nbsp;&nbsp;Console.WriteLine(bob.Length);<br /><br />just seems safer.<br /><br /></i></blockquote>
</td>
</tr>
</tbody>
</table>
</blockquote>
<br /><br /><br />Sorry, that's just not making sense; maybe you need to come up with a better example, but I can't see it.&nbsp; s can never be null here ... even if it was you'd sure as hell WANT an exception to be thrown, because it's exceptional ... you don't want to hide this
 kind of exception.
<blockquote></blockquote>
</div>
</blockquote>
<br /><br />OK, it appears that some of you never started out coding in ASM, C or C&#43;&#43; because you aren't able to envision a time and place where
<br /><br />1) dinosaurs ruled the planet<br />2) memory allocations were managed by the developer<br />3) some of them could fail for more reasons than just 'out of memory'.<br /><br />So,<br /><br />Console.WriteLine(new Object().ToString());<br /><br />Would be a great way to cause your application to fail catastrophically.<br /><br />It's also evident that from your point of view, failure is simply something that the end user can recover from.&nbsp; This is not the case when working on server software.&nbsp; You don't want your application to fail, you want it to retry.<br /><br />So, All I'm saying is that I've spent at least 1 decade forcing myself to remember these limitations and when I see<br /><br />Console.WriteLine(new Object().ToString());<br /><br />It feels 'wrong' to me because, in the past, it WAS wrong, based on my experience.<br /><br />I'm quite aware that it isn't wrong, and is, in fact, a simpler way to code.<br /><br />I really don't have anything more to say about it.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/c7005fe1b0b94e5182479dfa00865f91#c7005fe1b0b94e5182479dfa00865f91</link>
		<pubDate>Wed, 05 Dec 2007 18:47:58 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/c7005fe1b0b94e5182479dfa00865f91#c7005fe1b0b94e5182479dfa00865f91</guid>
		<dc:creator>ScanIAm</dc:creator>
		<slash:comments>41</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/ScanIAm/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - is &#39;new object().property&#39; or &#39;new object().method()&#39; a good idea?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">DinoViehland wrote:</div>
<div class="quoteBody">&#65279;
<blockquote>
<table class="quoteTable">
<tbody>
<tr>
<td valign="top" width="10"><img src="/Themes/AlmostGlass/images/icon-quote.gif"></td>
<td class="txt3"><strong>littleguru wrote:</strong>
<hr size="1">
<i>&#65279;<br /><br />The MyObject instance won't be collected by the GC if you are accessing any fields that held by that instance... otherwise - as said - it would be a heavy CLR (GC) bug!</i></td>
</tr>
</tbody>
</table>
</blockquote>
<br /><br />Just to shed a little light on the situation the typical example of this is using IntPtr's and the Dispose pattern.&nbsp; Such as:<br /><br />class MyDisposable : IDisposable {<br />&nbsp;&nbsp;&nbsp; private IntPtr _foo;<br />&nbsp;&nbsp;&nbsp; public void DoIt() {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SomePInvokeOperation(_foo);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;~MyDisposable() {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Dispose();<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp; public void Dispose() {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CloseMyHandle(_foo);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GC.SuppressFinalization(this);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br />Now you do: new MyDisposable().DoIt();&nbsp; The IntPtr is read and right after that read there are no longer any references to the MyDisposable() instance.&nbsp; Before SomePInvokeOperation can run the GC kicks in and&nbsp;collects the MyDisposable class.&nbsp; Next the finalizer
 thread runs which runs the finalizer&nbsp;which closes the native resource.&nbsp; Finally your SomePInvokeOperation runs and is operating on a _foo that is no longer valid.<br /><br />The worst case scenario here is that you can use this for a handle recycling attack which violates security.&nbsp; If you're lucky the app is just going to crash.&nbsp; Anyway, the way to fix this is to put a GC.KeepAlive(this); in DoIt() so that the object survives
 the lifetime of the call.&nbsp; But it's really only a problem when you're interacting with native resources which the GC doesn't understand and keep alive its self.&nbsp; So still not a bug, but a good thing to know about if you're doing any interop programming.</div>
</blockquote>
<br /><br />Let's sum up: I'm sure that the first parameter that is passed in with that method is a this pointer... Why would the GC mean that the instance should be collected, if I try to access a member variable later on? If I don't access it, it is fine because I'll
 never discover that the GC collected it.<br /><br />I'm accessing a private member of the class in the DoIt method. How can the GC collect the instance that is holding that before I access it. I thought the GC is only collecting if the instance is no longer reachable!<br /><br />Correct me if I'm wrong!</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/9c92fc1b04fe459988e39dfa00865ffb#9c92fc1b04fe459988e39dfa00865ffb</link>
		<pubDate>Wed, 05 Dec 2007 19:59:31 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/9c92fc1b04fe459988e39dfa00865ffb#9c92fc1b04fe459988e39dfa00865ffb</guid>
		<dc:creator>Christian Liensberger</dc:creator>
		<slash:comments>41</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/littleguru/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - is &#39;new object().property&#39; or &#39;new object().method()&#39; a good idea?</title>
		<description><![CDATA[<p>:O wow ,my god</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/7d10069296ad475f8b0f9dfa0086606b#7d10069296ad475f8b0f9dfa0086606b</link>
		<pubDate>Thu, 06 Dec 2007 09:36:14 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/7d10069296ad475f8b0f9dfa0086606b#7d10069296ad475f8b0f9dfa0086606b</guid>
		<dc:creator>yinxi88</dc:creator>
		<slash:comments>41</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/yinxi88/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - is &#39;new object().property&#39; or &#39;new object().method()&#39; a good idea?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">littleguru wrote:</div>
<div class="quoteBody">&#65279;<br /><br />I'm accessing a private member of the class in the DoIt method. How can the GC collect the instance that is holding that before I access it. I thought the GC is only collecting if the instance is no longer reachable!<br /><br />Correct me if I'm wrong!</div>
</blockquote>
<br /><br />Turns out this is only happens when interacting with PInvoke and unmanaged operations. Within managed code it doesn't happen.<br /><br /><a href="/ShowPost.aspx?PostID=362343#362343">Read Dino's post</a>.<br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/8a854a307120456a864e9dfa008660b8#8a854a307120456a864e9dfa008660b8</link>
		<pubDate>Thu, 06 Dec 2007 11:24:06 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/8a854a307120456a864e9dfa008660b8#8a854a307120456a864e9dfa008660b8</guid>
		<dc:creator>evildictaitor</dc:creator>
		<slash:comments>41</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/evildictaitor/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - is &#39;new object().property&#39; or &#39;new object().method()&#39; a good idea?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">evildictaitor wrote:</div>
<div class="quoteBody">&#65279;
<blockquote>
<table class="quoteTable">
<tbody>
<tr>
<td valign="top" width="10"><img src="/Themes/AlmostGlass/images/icon-quote.gif"></td>
<td class="txt3"><strong>littleguru wrote:</strong>
<hr size="1">
<i>&#65279;<br /><br />I'm accessing a private member of the class in the DoIt method. How can the GC collect the instance that is holding that before I access it. I thought the GC is only collecting if the instance is no longer reachable!<br /><br />Correct me if I'm wrong!</i></td>
</tr>
</tbody>
</table>
</blockquote>
<br /><br />Turns out this is only happens when interacting with PInvoke and unmanaged operations. Within managed code it doesn't happen.<br /><br /><a href="/ShowPost.aspx?PostID=362343#362343">Read Dino's post</a>.<br /></div>
</blockquote>
<br /><br />I thought that this has to do with PInvoke. But I guess it has to do while the PInvoke code is running not before that! <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif' alt='Smiley' /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/ce93588bcacb4b9d9ec99dfa0086610f#ce93588bcacb4b9d9ec99dfa0086610f</link>
		<pubDate>Thu, 06 Dec 2007 11:45:50 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/ce93588bcacb4b9d9ec99dfa0086610f#ce93588bcacb4b9d9ec99dfa0086610f</guid>
		<dc:creator>Christian Liensberger</dc:creator>
		<slash:comments>41</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/littleguru/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - is &#39;new object().property&#39; or &#39;new object().method()&#39; a good idea?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">littleguru wrote:</div>
<div class="quoteBody">&#65279;
<blockquote>
<table class="quoteTable">
<tbody>
<tr>
<td valign="top" width="10"><img src="/Themes/AlmostGlass/images/icon-quote.gif"></td>
<td class="txt3"><strong>evildictaitor wrote:</strong>
<hr size="1">
<i>&#65279;
<blockquote>
<table class="quoteTable">
<tbody>
<tr>
<td valign="top" width="10"><img src="/Themes/AlmostGlass/images/icon-quote.gif"></td>
<td class="txt3"><strong>littleguru wrote:</strong>
<hr size="1">
<i>&#65279;<br /><br />I'm accessing a private member of the class in the DoIt method. How can the GC collect the instance that is holding that before I access it. I thought the GC is only collecting if the instance is no longer reachable!<br /><br />Correct me if I'm wrong!</i></td>
</tr>
</tbody>
</table>
</blockquote>
<br /><br />Turns out this is only happens when interacting with PInvoke and unmanaged operations. Within managed code it doesn't happen.<br /><br /><a href="/ShowPost.aspx?PostID=362343#362343">Read Dino's post</a>.<br /></i></td>
</tr>
</tbody>
</table>
</blockquote>
<br /><br />I thought that this has to do with PInvoke. But I guess it has to do while the PInvoke code is running not before that! <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif' alt='Smiley' /></div>
</blockquote>
<br /><br />Yes. It reminds me of one of the really hard-to-repro bugs I've ever seen which was in an app designed to &quot;turn off&quot; the Windows key while in certain applications.<br /><br />Basically you have to interact with Windows and give them a delegate object which they call whenever a key is pressed, but sadly even delegate objects get garbage collected, at which point the next keystroke kills the application immediately. Took me weeks
 to find that bug.<br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/6933a8ea62d8440fb26e9dfa00866174#6933a8ea62d8440fb26e9dfa00866174</link>
		<pubDate>Thu, 06 Dec 2007 11:51:05 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/6933a8ea62d8440fb26e9dfa00866174#6933a8ea62d8440fb26e9dfa00866174</guid>
		<dc:creator>evildictaitor</dc:creator>
		<slash:comments>41</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/evildictaitor/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - is &#39;new object().property&#39; or &#39;new object().method()&#39; a good idea?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">evildictaitor wrote:</div>
<div class="quoteBody">&#65279;To protect against it you could do <br /><br />MyObject o = new MyObject();<br />var result = o.LongRunningMethod();<br />GC.KeepAlive(o);<br /><br />But in fairness this is a bug that should be fixed by Microsoft rather than coded around, and you should write an bugreport if you find in your code that this is happening.<br /></div>
</blockquote>
<br /><br />You could use KeepAlive, but it's probably better to fix the design of your code. This is definitely not a bug. <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif' alt='Smiley' /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/2a0cfd9294e041f080769dfa008661c8#2a0cfd9294e041f080769dfa008661c8</link>
		<pubDate>Tue, 11 Dec 2007 23:31:22 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/2a0cfd9294e041f080769dfa008661c8#2a0cfd9294e041f080769dfa008661c8</guid>
		<dc:creator>Curt Nichols</dc:creator>
		<slash:comments>41</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Curt Nichols/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - is &#39;new object().property&#39; or &#39;new object().method()&#39; a good idea?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">littleguru wrote:</div>
<div class="quoteBody">&#65279;The MyObject instance won't be collected by the GC if you are accessing any fields that held by that instance... otherwise - as said - it would be a heavy CLR (GC) bug!</div>
</blockquote>
<br /><br />This is incorrect, and it's not a bug. Objects referenced by fields of the MyObject&nbsp;instance will be collected only if when are no rooted references to them, not when the MyObject instance is collected. The MyObject instance may be collected even if there are
 other outstanding references to objects that its fields refer to. You can see for yourself
<a href="http://www.codeneverwritten.com/2007/12/where-did-my-object-go-part-2.html">
here</a>, code is included.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/be4c7bd04e1e428786c09dfa00866220#be4c7bd04e1e428786c09dfa00866220</link>
		<pubDate>Tue, 11 Dec 2007 23:37:39 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/be4c7bd04e1e428786c09dfa00866220#be4c7bd04e1e428786c09dfa00866220</guid>
		<dc:creator>Curt Nichols</dc:creator>
		<slash:comments>41</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Curt Nichols/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - is &#39;new object().property&#39; or &#39;new object().method()&#39; a good idea?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">Pop Catalin Sever wrote:</div>
<div class="quoteBody">&#65279;1) if <font face="Courier New"><font size="2">LongRunningMethod() acceses fields on MyObject instance the &quot;this&quot; parameter is passed on the stack to the method meaning you have a rooted reference to the object instance, the method call
 practicaly is like this<br /><br />newobj MyObject //Returns a reference in the stack <br />call </font></font><font face="Courier New"><font size="2">LongRunningMethod<br /></font></font><font face="Courier New"><font size="2"><br /></font></font></div>
</blockquote>
<br /><br />What you're not seeing is that the JITter helps the GC know when the reference is no longer needed. In this case the&nbsp;MyObject reference is needed only to invoke the call to LongRunningMethod, but isn't needed afterward. If a GC occurs during LongRunningMethod
 the instance may be collected if there are no other rooted references to the object.<br /><br />See <a href="http://www.codeneverwritten.com/2007/12/where-did-my-object-go-part-2.html">
here</a> if you want code to reproduce the behavior.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/6d9fea700f98448bb6db9dfa00866279#6d9fea700f98448bb6db9dfa00866279</link>
		<pubDate>Tue, 11 Dec 2007 23:43:30 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/6d9fea700f98448bb6db9dfa00866279#6d9fea700f98448bb6db9dfa00866279</guid>
		<dc:creator>Curt Nichols</dc:creator>
		<slash:comments>41</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Curt Nichols/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - is &#39;new object().property&#39; or &#39;new object().method()&#39; a good idea?</title>
		<description><![CDATA[<p>I would see <br /><br />new object().SomeMethod() <br /><br />as a 'smell' indicating that SomeMethod should be static ...</p>
<p>&nbsp;</p>
<p>Herbie</p>
<p>&nbsp;</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/0cd20830330044a7ae549dfa008662eb#0cd20830330044a7ae549dfa008662eb</link>
		<pubDate>Wed, 12 Dec 2007 14:44:39 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/0cd20830330044a7ae549dfa008662eb#0cd20830330044a7ae549dfa008662eb</guid>
		<dc:creator>Herbie Smith</dc:creator>
		<slash:comments>41</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Dr Herbie/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - is &#39;new object().property&#39; or &#39;new object().method()&#39; a good idea?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">Dr Herbie wrote:</div>
<div class="quoteBody">&#65279;<br />I would see <br /><br />new object().SomeMethod() <br /><br />as a 'smell' indicating that SomeMethod should be static ...
<p>Herbie<br /></p>
</div>
</blockquote>
<br /><br />Can this even be done in VB.NET?<br /><br />I'm trying to convert some sample code from c# that says:<br /><br /><font color="#0000ff" size="2">New</font><font size="2"> Application().run(f)<br /><br />But that doesnt' work in VB.NET.&nbsp; Is there an equivalant?
<p></p>
</font></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/30872219db0f48d8834f9dfa00866363#30872219db0f48d8834f9dfa00866363</link>
		<pubDate>Thu, 24 Jan 2008 19:25:05 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/30872219db0f48d8834f9dfa00866363#30872219db0f48d8834f9dfa00866363</guid>
		<dc:creator>shuff1203</dc:creator>
		<slash:comments>41</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/shuff1203/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - is &#39;new object().property&#39; or &#39;new object().method()&#39; a good idea?</title>
		<description><![CDATA[<p><pre>Dim o = New Application()
o.run(f)
</pre></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/f9b9729d67e64d31ba849dfa008663b6#f9b9729d67e64d31ba849dfa008663b6</link>
		<pubDate>Thu, 24 Jan 2008 19:33:53 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/f9b9729d67e64d31ba849dfa008663b6#f9b9729d67e64d31ba849dfa008663b6</guid>
		<dc:creator>JChung2006</dc:creator>
		<slash:comments>41</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/JChung2006/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - is &#39;new object().property&#39; or &#39;new object().method()&#39; a good idea?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">JChung2006 wrote:</div>
<div class="quoteBody">&#65279;<br />Dim o = New Application()<br />o.run(f)<br /></div>
</blockquote>
<br /><br />My quesiton was is there an equivalent to:<br /><br /><font size="2">
<p></font><font color="#0000ff" size="2">New</font><font size="2"> Application().run(f)<br /><br />I realize I could declare a var and use it.</p>
</font></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/48b957e833094958b4c09dfa0086640f#48b957e833094958b4c09dfa0086640f</link>
		<pubDate>Thu, 24 Jan 2008 19:59:45 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/48b957e833094958b4c09dfa0086640f#48b957e833094958b4c09dfa0086640f</guid>
		<dc:creator>shuff1203</dc:creator>
		<slash:comments>41</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/shuff1203/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - is &#39;new object().property&#39; or &#39;new object().method()&#39; a good idea?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">shuff1203 wrote:</div>
<div class="quoteBody">&#65279;<br />My quesiton was is there an equivalent to:<br /><font size="2"></font>
<p><font color="#0000ff" size="2">New</font><font size="2"> Application().run(f)<br /><br />I realize I could declare a var and use it.</font></p>
</div>
</blockquote>
<br /><br />Try declaring a function and passing that as the arguments:<br /><br />foo( New Application().run(f) )<br /><br />If that throws an error, then no you can't, otherwise you might need to declare the type of the variable you're assigning first.<br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/e3fbfa9b618b4bc993a49dfa00866466#e3fbfa9b618b4bc993a49dfa00866466</link>
		<pubDate>Thu, 24 Jan 2008 20:46:29 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/e3fbfa9b618b4bc993a49dfa00866466#e3fbfa9b618b4bc993a49dfa00866466</guid>
		<dc:creator>evildictaitor</dc:creator>
		<slash:comments>41</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/evildictaitor/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - is &#39;new object().property&#39; or &#39;new object().method()&#39; a good idea?</title>
		<description><![CDATA[<p><pre>GetType(Application).GetConstructor(New System.Type() {}).Invoke(New Object() {}).Run(f)</pre></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/81f4d92a85254190a3059dfa008664b6#81f4d92a85254190a3059dfa008664b6</link>
		<pubDate>Thu, 24 Jan 2008 20:55:40 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/81f4d92a85254190a3059dfa008664b6#81f4d92a85254190a3059dfa008664b6</guid>
		<dc:creator>JChung2006</dc:creator>
		<slash:comments>41</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/JChung2006/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - is &#39;new object().property&#39; or &#39;new object().method()&#39; a good idea?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">JChung2006 wrote:</div>
<div class="quoteBody">&#65279;
<pre>GetType(Application).GetConstructor(New System.Type() {}).Invoke(New Object() {}).Run(f)</pre>
</div>
</blockquote>
<br /><br />While your post is technically correct, using reflection just to inline a function is never a good idea.<br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/00536d82c802446da8729dfa00866501#00536d82c802446da8729dfa00866501</link>
		<pubDate>Thu, 24 Jan 2008 22:58:42 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/00536d82c802446da8729dfa00866501#00536d82c802446da8729dfa00866501</guid>
		<dc:creator>evildictaitor</dc:creator>
		<slash:comments>41</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/evildictaitor/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - is &#39;new object().property&#39; or &#39;new object().method()&#39; a good idea?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">evildictaitor wrote:</div>
<div class="quoteBody">&#65279;
<blockquote>
<table class="quoteTable">
<tbody>
<tr>
<td valign="top" width="10"><img src="/Themes/AlmostGlass/images/icon-quote.gif"></td>
<td class="txt3"><strong>JChung2006 wrote:</strong>
<hr size="1">
<i>&#65279;
<pre>GetType(Application).GetConstructor(New System.Type() {}).Invoke(New Object() {}).Run(f)</pre>
</i></td>
</tr>
</tbody>
</table>
</blockquote>
<br /><br />While your post is technically correct, using reflection just to inline a function is never a good idea.<br /></div>
</blockquote>
<br /><br />Ya, but he did answer the question, that is a way to do it with just oneline of code in vb.net...</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/b9a2fb7bd91f423f822b9dfa0086654f#b9a2fb7bd91f423f822b9dfa0086654f</link>
		<pubDate>Fri, 25 Jan 2008 02:46:01 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/b9a2fb7bd91f423f822b9dfa0086654f#b9a2fb7bd91f423f822b9dfa0086654f</guid>
		<dc:creator>shuff1203</dc:creator>
		<slash:comments>41</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/shuff1203/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - is &#39;new object().property&#39; or &#39;new object().method()&#39; a good idea?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">shuff1203 wrote:</div>
<div class="quoteBody">&#65279;<br />Ya, but he did answer the question, that is a way to do it with just oneline of code in vb.net...</div>
</blockquote>
<br /><br />Well, sort of. The inlined expression in C# does a very different control path to the thing he showed there, which can experience considerable slowdown, since reflection is a relatively expensive process (computationally speaking), and is never a good idea
 if there's an alternative.<br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/af0501c3d3a44efeb2bc9dfa00866595#af0501c3d3a44efeb2bc9dfa00866595</link>
		<pubDate>Fri, 25 Jan 2008 03:11:26 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/af0501c3d3a44efeb2bc9dfa00866595#af0501c3d3a44efeb2bc9dfa00866595</guid>
		<dc:creator>evildictaitor</dc:creator>
		<slash:comments>41</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/evildictaitor/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - is &#39;new object().property&#39; or &#39;new object().method()&#39; a good idea?</title>
		<description><![CDATA[<p>If new String(&quot;Bob&quot;) could not be created, then an exception would be thrown, would it not?<br /><br />Then .Length would never be called.<br /><br />Also, you worry too much.<br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/bfea7c4b6dab4e889dbe9dfa00866603#bfea7c4b6dab4e889dbe9dfa00866603</link>
		<pubDate>Fri, 25 Jan 2008 04:56:49 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/bfea7c4b6dab4e889dbe9dfa00866603#bfea7c4b6dab4e889dbe9dfa00866603</guid>
		<dc:creator>Minh</dc:creator>
		<slash:comments>41</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Minh/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - is &#39;new object().property&#39; or &#39;new object().method()&#39; a good idea?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">evildictaitor wrote:</div>
<div class="quoteBody">&#65279;
<blockquote>
<table class="quoteTable">
<tbody>
<tr>
<td valign="top" width="10"><img src="/Themes/AlmostGlass/images/icon-quote.gif"></td>
<td class="txt3"><strong>shuff1203 wrote:</strong>
<hr size="1">
<i>&#65279;<br />Ya, but he did answer the question, that is a way to do it with just oneline of code in vb.net...</i></td>
</tr>
</tbody>
</table>
</blockquote>
<br /><br />Well, sort of. The inlined expression in C# does a very different control path to the thing he showed there, which can experience considerable slowdown, since reflection is a relatively expensive process (computationally speaking), and is never a good idea
 if there's an alternative.<br /></div>
</blockquote>
<p>You missed the point so please just drop it.&nbsp; Yes, reflection is slower than if the references were already there, but guess what?&nbsp; Reflection is still faster than a network roundtrip or a disk seek by several orders of magnitude.</p>
<p>&quot;Premature optimization is the root of all evil.&quot; -C. A. R. Hoare</p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/1e1c9bd56b0648ce99ae9dfa0086665a#1e1c9bd56b0648ce99ae9dfa0086665a</link>
		<pubDate>Fri, 25 Jan 2008 05:02:49 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/1e1c9bd56b0648ce99ae9dfa0086665a#1e1c9bd56b0648ce99ae9dfa0086665a</guid>
		<dc:creator>JChung2006</dc:creator>
		<slash:comments>41</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/JChung2006/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - is &#39;new object().property&#39; or &#39;new object().method()&#39; a good idea?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">JChung2006 wrote:</div>
<div class="quoteBody">&#65279;
<p>You missed the point so please just drop it.&nbsp; Yes, reflection is slower than if the references were already there, but guess what?&nbsp; Reflection is still faster than a network roundtrip or a disk seek by several orders of magnitude.</p>
<p>&quot;Premature optimization is the root of all evil.&quot; -C. A. R. Hoare</p>
</div>
</blockquote>
<br /><br />Maybe, but compiler optimisations is one of the reasons your computer is getting faster year-on-year. It's not all hardware you know.<br /><br />And even if reflection is faster than a network roundtrip it's less maintainable code, and automatic reasoning agents can't reason over reflection code, so the compiler can't do any optimisations over the function call.<br /><br />But I'll assume I've missed the point, and stop pressing the issue.<br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/add28afac2ff49ab94ed9dfa008666af#add28afac2ff49ab94ed9dfa008666af</link>
		<pubDate>Fri, 25 Jan 2008 06:30:44 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/259414-is-new-objectproperty-or-new-objectmethod-a-good-idea/add28afac2ff49ab94ed9dfa008666af#add28afac2ff49ab94ed9dfa008666af</guid>
		<dc:creator>evildictaitor</dc:creator>
		<slash:comments>41</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/evildictaitor/Discussions/RSS</wfw:commentRss>
	</item>
</channel>
</rss>