Solved

Convert classes CType

Posted on 2008-10-29
2
277 Views
Last Modified: 2013-11-07
Hi!

I wonder If I can convert a class from one type to another

If I have
Public Class Test1
End Class

Public Class Test2
  Inherits Test1
End Class

Dim myTest1 as New Test1
Dim myTest2 = Ctype(mytest1, Test2)
0
Comment
Question by:AWestEng
2 Comments
 
LVL 13

Accepted Solution

by:
TechTiger007 earned 500 total points
ID: 22829732

You can convert an object of type Test2 into Test1 but you cannot convert Test1 into Test2, because a class reference can always point to an object of that particular type or of any derived type but not any other type.

In this case Test2 is derived from Test1 so

Dim myTest2 as New Test2
Dim myTest1 as Test1 = Ctype(mytest2, Test1)

would be valid not the other way around
0
 
LVL 1

Author Comment

by:AWestEng
ID: 22829821
My design is then faulty.
I will make a new question for a redesign
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now