<?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>CSharpBits:The is and as Operators</title><link>http://blogs.msdn.com/jeff_adkins/archive/2004/03/16/90494.aspx</link><description>CSharp Bits is a tutorial-based digest that explains the C# programming language. It evolves, covering prerequisite topics and is currently broad in coverage rather than getting deep into a specific topic. That will come after a basis has been established.</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: CSharpBits:The is and as Operators</title><link>http://blogs.msdn.com/jeff_adkins/archive/2004/03/16/90494.aspx#90565</link><pubDate>Tue, 16 Mar 2004 20:26:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:90565</guid><dc:creator>Jerry Pisk</dc:creator><description>Why exactly does &amp;quot;is&amp;quot; return false when the object is null? Did the C# specification change and null is no longer a valid object value?</description></item><item><title>re: CSharpBits:The is and as Operators</title><link>http://blogs.msdn.com/jeff_adkins/archive/2004/03/16/90494.aspx#90669</link><pubDate>Tue, 16 Mar 2004 23:21:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:90669</guid><dc:creator>Ron</dc:creator><description>Jeff,&lt;br&gt;&lt;br&gt;As always, thanks for these articles. &lt;br&gt;&lt;br&gt;1) how does the &amp;quot;is&amp;quot; operator check that the type of object is the same?&lt;br&gt;&lt;br&gt;2) Why do we need a cast operator? Is it not better to always use  the &amp;quot;as&amp;quot; operator (and check for null)?</description></item><item><title>re: CSharpBits:The is and as Operators</title><link>http://blogs.msdn.com/jeff_adkins/archive/2004/03/16/90494.aspx#90722</link><pubDate>Wed, 17 Mar 2004 00:49:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:90722</guid><dc:creator>Jeff Adkins</dc:creator><description>1)I'm not certain, but I assume it's doing a typeOf call or a reflection runtime GetType() call.  Here's a reference..&lt;br&gt;&lt;a target="_new" href="http://msdn.microsoft.com/library/en-us/csref/html/vclrftypeofpg.asp?frame=true"&gt;http://msdn.microsoft.com/library/en-us/csref/html/vclrftypeofpg.asp?frame=true&lt;/a&gt;&lt;br&gt;&lt;br&gt;2)The cast will raise the InvalidCastException for you to catch and you have to handle your own exception handling with the &amp;quot;as&amp;quot; operator.  Otherwise, you're making a good point when it comes to reference types.  Casting is used more for value types.&lt;br&gt;&lt;br&gt;</description></item><item><title>re: CSharpBits:The is and as Operators-Why exactly does "is" return false when the object is null? Did the C# specification change and null is no longer a valid object value?</title><link>http://blogs.msdn.com/jeff_adkins/archive/2004/03/16/90494.aspx#90732</link><pubDate>Wed, 17 Mar 2004 01:13:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:90732</guid><dc:creator>Jeff Adkins</dc:creator><description>The &amp;quot;is&amp;quot; Operator is trying to determine if a cast can be made without error.  If the object reference is null, that means it is not pointing to a current object in memory and an error would be raised when the framework tries to perform a typeOf operator or a GetType() call on a null value.  Also, I believe a cast on reference variable with a current null value would raise an exception.  These are my assumptions.  If you're still curious, try testing these two scenarios.  See if you can do a GetType or use the typeOf operator on a ref variable with a null value.  And, separtely, try to do a cast on this variable with a null value.&lt;br&gt;&lt;br&gt;</description></item></channel></rss>