From: Dave T on
I have a type *Address* and a type *ResidentialAddress* which inherits
Address. When I try to execute SOMECLASS.ResAddr = OTHERCLASS.Addr I get the
inevitable type mis-match error "unable to cast type ObjectModel.Address to
Type ObjectModel.ResidentialAddress" I was thinking that since
ResidentialAddress inherits Address, there must be some way to do this
assignment
From: Cor Ligthert[MVP] on
Hello Dave,

Yea but commonly your properties have the same names if you don't cast them
using an interface.

I would not use a class name Address, that is to ambiguous (to often used)
in Net.

Cor

"Dave T" <DaveT(a)discussions.microsoft.com> wrote in message
news:A8A33D7C-C3B9-4101-83A9-68190EE1BDB5(a)microsoft.com...
> I have a type *Address* and a type *ResidentialAddress* which inherits
> Address. When I try to execute SOMECLASS.ResAddr = OTHERCLASS.Addr I get
> the
> inevitable type mis-match error "unable to cast type ObjectModel.Address
> to
> Type ObjectModel.ResidentialAddress" I was thinking that since
> ResidentialAddress inherits Address, there must be some way to do this
> assignment

From: Armin Zingler on
Dave T schrieb:
> I have a type *Address* and a type *ResidentialAddress* which inherits
> Address. When I try to execute SOMECLASS.ResAddr = OTHERCLASS.Addr I get the
> inevitable type mis-match error "unable to cast type ObjectModel.Address to
> Type ObjectModel.ResidentialAddress" I was thinking that since
> ResidentialAddress inherits Address, there must be some way to do this
> assignment

You're trying to assign an Address to a ResidentialAddress. Not every
Address is a ResidentialAddress. OTHERCLASS.Addr can also be a WhateverAddress
which is not a ResidentialAddress. Or it can just be an Address. Therefore it fails.

If you know that OTHERCLASS.Addr _always_ returns a ResidentialAddress,
you can type cast the reference
SOMECLASS.ResAddr = DirectCast(OTHERCLASS.Addr, ResidentialAddress)

Or, if possible, the type of OTHERCLASS.Addr can be changed to ResidentialAddress.



--
Armin