Casting an object to a type that the object inherits from - C# - TechRepublic
Question
March 14, 2008 at 12:08 PM
bnemec

Casting an object to a type that the object inherits from – C#

by bnemec . Updated 18 years, 4 months ago

I have a C# object of type _BaseFormDataEntry.
I also have a C# object that inherits from the the _BaseFormDataEntry object called FormDetailSearch.
i have a property that returns a _BaseFormDataEntry typed object.
in that property the return value is of _BaseFormDataEntry type and i would like to cast the object FormDetailSearch (which inherits from _BaseFormDataEntry) into and object of type _BaseFormDataEntry.

does this type of conversion make sense? if not, what would be the correct way?

as it is right now the property throws and exception when it tries to perform the cast and basically says it cannot cast the object FormDetailSearch into object of type _BaseFormDataEntry. what’s am i doing wrong?

This discussion is locked

All Comments