Solved

Convert classes CType

Posted on 2008-10-29
2
284 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

839 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