{"id":135,"date":"2010-12-03T12:03:49","date_gmt":"2010-12-03T17:03:49","guid":{"rendered":"http:\/\/wukenny.host-ed.net\/?p=135"},"modified":"2010-12-03T12:03:49","modified_gmt":"2010-12-03T17:03:49","slug":"when-to-use-is-and-when-to-use-as-in-c","status":"publish","type":"post","link":"http:\/\/kennywu.info\/?p=135","title":{"rendered":"When to use &#8220;is&#8221; and when to use &#8220;as&#8221; in C#"},"content":{"rendered":"<p>The <strong> is <\/strong> operator accepts an object on the left hand side and a type on the right. It returns <em>true<\/em> if the run-time type of the object on the left is compatible with the type on the right. Always use <strong>is<\/strong> before making the type cast.<br \/>\nThe <strong>as<\/strong> actually cast the type on the left to the type on the right, <em>null<\/em> will be returned if the conversion fails.<\/p>\n<ol>\n<li><strong>as<\/strong> is preferred, because it is more efficient (the conversion is already done with the <strong>as<\/strong> operator. <\/li>\n<li>For value-type variables, like <em>int, <\/em> <em>char<\/em> you can only use <strong>is<\/strong> to convert from one type to another.\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>The is operator accepts an object on the left hand side and a type on the right. It returns true if the run-time type of the object on the left is compatible with the type on the right. Always use &hellip; <a href=\"http:\/\/kennywu.info\/?p=135\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[34],"class_list":["post-135","post","type-post","status-publish","format-standard","hentry","category-programing","tag-is"],"_links":{"self":[{"href":"http:\/\/kennywu.info\/index.php?rest_route=\/wp\/v2\/posts\/135","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/kennywu.info\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/kennywu.info\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/kennywu.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/kennywu.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=135"}],"version-history":[{"count":0,"href":"http:\/\/kennywu.info\/index.php?rest_route=\/wp\/v2\/posts\/135\/revisions"}],"wp:attachment":[{"href":"http:\/\/kennywu.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=135"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/kennywu.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=135"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/kennywu.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=135"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}