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)
{
...

they would be saying that if the m_car variable is of the type MiniCooper then do something.

The "as" keyword is used to "cast" a type to another type. So you could write

if(m_car is MiniCooper)
{
MiniCooper mc = m_car as MiniCooper;

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".

I hope this helps.

Technorati Tags
[feed], [feed], [feed], [feed], [feed], [feed], [feed], [feed], [feed], [feed]

Related Wikipedia Documents
, , , , , , , , , ,

My Related Documents
,

Related Amazon Books
UML Pocket Reference: /, BusinessObjects: The Complete Reference (Complete Reference S.): /, Microsoft Visual C# .NET (Core Reference): /, Visual C#.NET Language Reference: /, Successful Keyword Searching: Initiating Research on Popular Topics Using Electronic Databases: /, Automatic Keyword Classification for Information Retrieval: /, DHTML Utopia: Modern Web Design Using JavaScript & DOM: /, JavaScript: The Definitive Guide: /

Related Images From Flickr
[[posterous-content:DInBsGyDprbevscbAqir]][[posterous-content:tCqFDceffackeocgmFHj]][[posterous-content:woJfbobfvumijckBwDuu]][[posterous-content:JjldhnumJhoBzlmcfcpi]]