?
Solved

Convert classes CType

Posted on 2008-10-29
2
Medium Priority
?
292 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 2000 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

Congratulations! You’re Certified – Now What?

Starting a new career can be overwhelming. Becoming certified in your field of expertise is a great start, but where do you go from here?  Here are some tips to help you on your career journey.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

764 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