Solved

Convert classes CType

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
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:…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

762 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

23 Experts available now in Live!

Get 1:1 Help Now