. Topicala Page Index Token

A Journal about the experiences I have developing little applications in C#, Perl, Html and Javascript and talking about things new things that I use. Always Geeky; Always Nerdy; Always poor Grammer!

I am a Software Analyst Developer working in Southport, England but living in Liverpool. I develop mainly in C# and ASP.Net. I have been developing comercial software for several years now. I maintain this site (hosted at SwitchMedia UK) as a way of exploring new technologies (such as AJAX) and just generally talking about techie geek issues. This site is developed through a host of Perl scripts and a liberal use of Javascript. I enjoy experimenting with new technologies and anything that I make I host here.

Quick Search

Web www.kinlan.co.uk

Thursday, November 24, 2005

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

Comments: [Add New]

Thanks! I actually *was* looking for "c# instanceof" and found this post!

By Anonymous Sjoerd Visscher, at Friday, May 19, 2006 2:35:00 PM

It helped! Thanks :)

By Anonymous Anonymous, at Thursday, March 15, 2007 1:29:00 PM

Glad I could help :)

By Blogger Paul Kinlan, at Thursday, March 15, 2007 2:42:00 PM

Thanks for help. I found answer on your post.

By Blogger den123, at Saturday, May 12, 2007 8:24:00 AM

Thanks! I found answer in your post

By Blogger den123, at Saturday, May 12, 2007 8:27:00 AM

I think it's people like me who switch from Java to C# that use such queries. It really is the fastest way to find how "instanceof" is in C#... Thanks a lot!

By Blogger dstozek, at Wednesday, October 24, 2007 8:21:00 AM

Hey dude, "c# instanceof" query gives your site as a first link on google!

Lots of kudos to actually posting the proper way :)

Greets from NL.

By Blogger Vladimir Lazarenko, at Thursday, January 24, 2008 6:30:00 PM

Thanks for the compliments. If you need any help please don't hesitate to email me.

By Blogger Paul Kinlan, at Thursday, January 24, 2008 7:33:00 PM

Thank you! Exactly what I was looking for.

By Anonymous Anonymous, at Thursday, April 10, 2008 7:42:00 PM