<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Prefix-casting versus as-casting in C#</title>
	<atom:link href="http://gen5.info/q/2008/06/13/prefix-casting-versus-as-casting-in-c/feed/" rel="self" type="application/rss+xml" />
	<link>http://gen5.info/q/2008/06/13/prefix-casting-versus-as-casting-in-c/</link>
	<description>Towards Intelligent Systems</description>
	<pubDate>Thu, 20 Nov 2008 15:34:59 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
		<item>
		<title>By: Anu Viswan</title>
		<link>http://gen5.info/q/2008/06/13/prefix-casting-versus-as-casting-in-c/#comment-719</link>
		<dc:creator>Anu Viswan</dc:creator>
		<pubDate>Tue, 26 Aug 2008 17:38:12 +0000</pubDate>
		<guid isPermaLink="false">http://gen5.info/q/?p=31#comment-719</guid>
		<description>Thanks Paul for your kind reply. I understand the speed difference is trivial and doesnt really makes too much impact in real life application. Only thing that would matter is how each handle exception, which again you were spot on that its better to catch an exception earlier than face null later.

I was just curious about the differnce. After i read your article, i tried out my little study on differnce and it seems like prefix casting uses "castclass" function in the IL code generated while "as" casting would use isinst.

Reading about these IL commands, made me wunder again.

Did you happen to check out the differnce in IL ?</description>
		<content:encoded><![CDATA[<p>Thanks Paul for your kind reply. I understand the speed difference is trivial and doesnt really makes too much impact in real life application. Only thing that would matter is how each handle exception, which again you were spot on that its better to catch an exception earlier than face null later.</p>
<p>I was just curious about the differnce. After i read your article, i tried out my little study on differnce and it seems like prefix casting uses &#8220;castclass&#8221; function in the IL code generated while &#8220;as&#8221; casting would use isinst.</p>
<p>Reading about these IL commands, made me wunder again.</p>
<p>Did you happen to check out the differnce in IL ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul Houle</title>
		<link>http://gen5.info/q/2008/06/13/prefix-casting-versus-as-casting-in-c/#comment-712</link>
		<dc:creator>Paul Houle</dc:creator>
		<pubDate>Mon, 25 Aug 2008 22:53:35 +0000</pubDate>
		<guid isPermaLink="false">http://gen5.info/q/?p=31#comment-712</guid>
		<description>@Anu,

    according to reports I've seen,  the performance of as- and prefix casts have largely converged as of .net 3.5.  It would be interesting to run tests on mono as well.

    At this point,  I think people should use whatever convention they think is better from a sofware engineering standpoint.  In most cases,  I think it's better to get an exception early rather than face a null pointer deference later.  On the other hand,  there are definitely cases where the as-cast semantics are exactly what you want.</description>
		<content:encoded><![CDATA[<p>@Anu,</p>
<p>    according to reports I&#8217;ve seen,  the performance of as- and prefix casts have largely converged as of .net 3.5.  It would be interesting to run tests on mono as well.</p>
<p>    At this point,  I think people should use whatever convention they think is better from a sofware engineering standpoint.  In most cases,  I think it&#8217;s better to get an exception early rather than face a null pointer deference later.  On the other hand,  there are definitely cases where the as-cast semantics are exactly what you want.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anu Viswan</title>
		<link>http://gen5.info/q/2008/06/13/prefix-casting-versus-as-casting-in-c/#comment-710</link>
		<dc:creator>Anu Viswan</dc:creator>
		<pubDate>Mon, 25 Aug 2008 17:12:30 +0000</pubDate>
		<guid isPermaLink="false">http://gen5.info/q/?p=31#comment-710</guid>
		<description>Hi
I would disagree with you on the latter part in which you mentioned "as" casting is faster.

Can you provide some code sample to support your claim ??

Thanks
Anu</description>
		<content:encoded><![CDATA[<p>Hi<br />
I would disagree with you on the latter part in which you mentioned &#8220;as&#8221; casting is faster.</p>
<p>Can you provide some code sample to support your claim ??</p>
<p>Thanks<br />
Anu</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Petar Petrov</title>
		<link>http://gen5.info/q/2008/06/13/prefix-casting-versus-as-casting-in-c/#comment-529</link>
		<dc:creator>Petar Petrov</dc:creator>
		<pubDate>Thu, 19 Jun 2008 08:46:05 +0000</pubDate>
		<guid isPermaLink="false">http://gen5.info/q/?p=31#comment-529</guid>
		<description>I totally agree with Will.
I always use "as" operator over "is"+"as". However there is situations where I want to force the type so I use the prefix cast.</description>
		<content:encoded><![CDATA[<p>I totally agree with Will.<br />
I always use &#8220;as&#8221; operator over &#8220;is&#8221;+&#8221;as&#8221;. However there is situations where I want to force the type so I use the prefix cast.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Maarten Oosterhoff</title>
		<link>http://gen5.info/q/2008/06/13/prefix-casting-versus-as-casting-in-c/#comment-528</link>
		<dc:creator>Maarten Oosterhoff</dc:creator>
		<pubDate>Thu, 19 Jun 2008 07:15:34 +0000</pubDate>
		<guid isPermaLink="false">http://gen5.info/q/?p=31#comment-528</guid>
		<description>Another difference is that value types cannot be cast using the 'as' keyword, you must us prefix-casting for value-types.
I usually use the is/as keyword, I find that works best for me to understand the code.
Nice article though!</description>
		<content:encoded><![CDATA[<p>Another difference is that value types cannot be cast using the &#8216;as&#8217; keyword, you must us prefix-casting for value-types.<br />
I usually use the is/as keyword, I find that works best for me to understand the code.<br />
Nice article though!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Zack Owens</title>
		<link>http://gen5.info/q/2008/06/13/prefix-casting-versus-as-casting-in-c/#comment-527</link>
		<dc:creator>Zack Owens</dc:creator>
		<pubDate>Wed, 18 Jun 2008 22:10:05 +0000</pubDate>
		<guid isPermaLink="false">http://gen5.info/q/?p=31#comment-527</guid>
		<description>I'm not quite sure there is a situation that would require one type of cast over the other when you are dealing with classes or interfaces. Both are interchangeable syntactically and logically.

But also keep in mind that the as operator will only work for classes and interfaces. You must use the prefix cast when working with an enum or struct. The is operator, however, will work with enums and structs.</description>
		<content:encoded><![CDATA[<p>I&#8217;m not quite sure there is a situation that would require one type of cast over the other when you are dealing with classes or interfaces. Both are interchangeable syntactically and logically.</p>
<p>But also keep in mind that the as operator will only work for classes and interfaces. You must use the prefix cast when working with an enum or struct. The is operator, however, will work with enums and structs.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim C</title>
		<link>http://gen5.info/q/2008/06/13/prefix-casting-versus-as-casting-in-c/#comment-526</link>
		<dc:creator>Tim C</dc:creator>
		<pubDate>Wed, 18 Jun 2008 20:20:22 +0000</pubDate>
		<guid isPermaLink="false">http://gen5.info/q/?p=31#comment-526</guid>
		<description>"as" is faster? Sample code to back that up? In my testing it  was for all intents and purposes EXACTLY the same.</description>
		<content:encoded><![CDATA[<p>&#8220;as&#8221; is faster? Sample code to back that up? In my testing it  was for all intents and purposes EXACTLY the same.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sebastian</title>
		<link>http://gen5.info/q/2008/06/13/prefix-casting-versus-as-casting-in-c/#comment-525</link>
		<dc:creator>Sebastian</dc:creator>
		<pubDate>Wed, 18 Jun 2008 19:53:42 +0000</pubDate>
		<guid isPermaLink="false">http://gen5.info/q/?p=31#comment-525</guid>
		<description>I don't think articles about performance in .Net 1.1 should be used as a reference in 2008. Just read the article's comments or try it yourself before making such conclusions.
IF you want performance then do the _exact opposite_ of your "IBobbable" example. The first snippet (as) will use isinst (and a branch instruction) whereas the is-cast snippet will use isinst and castclass. A quick test shows a performance gain of about 12%, whew! This as-null pattern is the only place I use that operator. And now guess which use of "as" can be found in the "as keyword [C#]" SDK article ;) .</description>
		<content:encoded><![CDATA[<p>I don&#8217;t think articles about performance in .Net 1.1 should be used as a reference in 2008. Just read the article&#8217;s comments or try it yourself before making such conclusions.<br />
IF you want performance then do the _exact opposite_ of your &#8220;IBobbable&#8221; example. The first snippet (as) will use isinst (and a branch instruction) whereas the is-cast snippet will use isinst and castclass. A quick test shows a performance gain of about 12%, whew! This as-null pattern is the only place I use that operator. And now guess which use of &#8220;as&#8221; can be found in the &#8220;as keyword [C#]&#8221; SDK article <img src='http://gen5.info/q/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> .</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cristian</title>
		<link>http://gen5.info/q/2008/06/13/prefix-casting-versus-as-casting-in-c/#comment-524</link>
		<dc:creator>cristian</dc:creator>
		<pubDate>Wed, 18 Jun 2008 19:14:31 +0000</pubDate>
		<guid isPermaLink="false">http://gen5.info/q/?p=31#comment-524</guid>
		<description>Hi there, nice post. I think you should mention or write a post about about explicit type conversion. It's an important distinction of "prefix-casting".</description>
		<content:encoded><![CDATA[<p>Hi there, nice post. I think you should mention or write a post about about explicit type conversion. It&#8217;s an important distinction of &#8220;prefix-casting&#8221;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Janko</title>
		<link>http://gen5.info/q/2008/06/13/prefix-casting-versus-as-casting-in-c/#comment-523</link>
		<dc:creator>Janko</dc:creator>
		<pubDate>Tue, 17 Jun 2008 19:22:14 +0000</pubDate>
		<guid isPermaLink="false">http://gen5.info/q/?p=31#comment-523</guid>
		<description>Very good article!</description>
		<content:encoded><![CDATA[<p>Very good article!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
