But suppose I have an instance of something that is /just/ a Vehicle, as
in
"Vehicle v = new Vehicle();". Such an instance doesn't represent a Car,
or a
Boat, or an Airplane (yet). What I'm asking is how to place this
information
/into/ a new Car, Boat, or Airplane.
in
message KK,
It does, but your logic is wrong, because a Vehicle can be
something
that is not a Car, but a Car is always a Vehicle.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
"K.K." <kkaitan [at] gmail [dot] com> wrote in message
Nicholas,
Sorry, I guess I wasn't clear. I'm saying that I have an instance of
a
Vehicle (the base class). Now I'd like to construct a new instance of
a
Car
whose base-class fields are equal to the Vehicle instance. I guess
it's
sort
of like a copy constructor for Car, except that I'm not using another
Car
as
the basis for the copying, but rather a Vehicle.
Hope that makes a little more sense. Thanks again!
- KK
"Nicholas Paldino [.NET/C# MVP]" <
[email protected]>
wrote
in
message K.K.,
This isn't a good idea. What if you have a class, Airplane,
derived
from Vehicle, and then pass that to a Car instance to be cloned? An
Airplane definitely isn't a car, so it shouldn't really work.
What is it that you are trying to do? If anything, a Car should
clone
a
Car, or anything deriving from Car.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
"K.K." <kkaitan [at] gmail [dot] com> wrote in message
Suppose I have a class called Vehicle with many fields. Now I make
a
new
class derived from Vehicle called Car. I'd like to make a method
to
copy
the
data from a Vehicle instance to a Car instance. Is writing a long
series
of
assignments in a Clone() statement my only option?
I know that I can write a Clone method using MemberwiseClone(),
but
my
understanding is that the object created by MemberwiseClone is of
the
same
type.