Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Is it possible to cast down to an object that doesnt exist?

 

ie

 

temp = (SomeClass)objInstance

 

where objInstance is an instance of a parent object, and SomeClass is the object I want. Note that objInstance is not an instance of SomeClass, just its parent

  • Administrators
Posted
Is it possible to cast down to an object that doesnt exist?

 

ie

 

temp = (SomeClass)objInstance

 

where objInstance is an instance of a parent object, and SomeClass is the object I want. Note that objInstance is not an instance of SomeClass, just its parent

 

If temp is declared as the parent object then yes, you can make it equal to a sub-class. In fact you can always implicitly cast to a base class i.e. you don't even need the (...) bit.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...