Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / June 2007

Tip: Looking for answers? Try searching our database.

Copying a derived type to another type that inherits from derived type Options

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bob Jones - 29 Jun 2007 22:21 GMT
Ok, I am curious if this can be done in C# 2.0 via some internal .net
functionality or if I have to do a coversion myself such as a copy
construtor or override the explicit operator.

I have 3 classes.

ClassA
ClassB which derives from ClassA
ClassC which derives from ClassA as well

I can implicitly convert to ClassA from ClassB and ClassC. Easy
enough

I would like to convert ClassB to ClassA and then create a new
instance of ClassC and use the converted ClassA to fill in the
derived
methods and properties in ClassC without having to write code that
literally copies values from one class to the other. Is this
possible?

Psuedo Code:

ClassB classb = new ClassB();
ClassC classc = (ClassC)(ClassA)classb; //this doesn't work but you
get the point.

Thanks!!
Bob Jones - 29 Jun 2007 22:26 GMT
> Ok, I am curious if this can be done in C# 2.0 via some internal .net
> functionality or if I have to do a coversion myself such as a copy
[quoted text clipped - 23 lines]
>
> Thanks!!

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.