Google Search: c# instanceof

A couple of people have come to my site with the query “c# instanceof”. I know how I get found for this. I copied an “instanceof” javascript method and talked about it in one of my entries.The only relation to c# that I can think of would be the “is” and “as” keywords.”is” can be used to test what type of object an object reference is. For instance [no pun intend, or thought of I think :)] a developer could write:if(m_car is MiniCooper){.


This content originally appeared on Modern Web Development with Chrome and was authored by Paul Kinlan

<p>A couple of people have come to my site with the query "c# instanceof". I know how I get found for this. I copied an "instanceof" javascript method and talked about it in one of my entries.<p />The only relation to c# that I can think of would be the "is" and "as" keywords.<p />"is" can be used to test what type of object an object reference is. For instance [no pun intend, or thought of I think :)] a developer could write:if(m_car is MiniCooper){...<p />they would be saying that if the m_car variable is of the type MiniCooper then do something.<p />The "as" keyword is used to "cast" a type to another type. So you could write<p>if(m_car is MiniCooper){MiniCooper mc = m_car as MiniCooper;</p><p>The "as" keyword is slightly differnt to the Explicit cast (MiniCooper mc = (MiniCooper) m_car; because if the cast dosn't work with an "as" then the mc local variable will be null, rather than throwing an "InvalidCastException".</p><p>I hope this helps.</p><p /></p>


This content originally appeared on Modern Web Development with Chrome and was authored by Paul Kinlan


Print Share Comment Cite Upload Translate Updates
APA

Paul Kinlan | Sciencx (2005-11-24T00:00:00+00:00) Google Search: c# instanceof. Retrieved from https://www.scien.cx/2005/11/24/google-search-c-instanceof/

MLA
" » Google Search: c# instanceof." Paul Kinlan | Sciencx - Thursday November 24, 2005, https://www.scien.cx/2005/11/24/google-search-c-instanceof/
HARVARD
Paul Kinlan | Sciencx Thursday November 24, 2005 » Google Search: c# instanceof., viewed ,<https://www.scien.cx/2005/11/24/google-search-c-instanceof/>
VANCOUVER
Paul Kinlan | Sciencx - » Google Search: c# instanceof. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2005/11/24/google-search-c-instanceof/
CHICAGO
" » Google Search: c# instanceof." Paul Kinlan | Sciencx - Accessed . https://www.scien.cx/2005/11/24/google-search-c-instanceof/
IEEE
" » Google Search: c# instanceof." Paul Kinlan | Sciencx [Online]. Available: https://www.scien.cx/2005/11/24/google-search-c-instanceof/. [Accessed: ]
rf:citation
» Google Search: c# instanceof | Paul Kinlan | Sciencx | https://www.scien.cx/2005/11/24/google-search-c-instanceof/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.