Solved

Convert classes CType

Posted on 2008-10-29
2
286 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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 …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

733 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