473,407 Members | 2,320 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Casting to Custom Classes

Okay, this should be a simple thing, but I can't seemto find the right
documentation on it. I created a custom class that inherits from a well
known class. For example:
Class MyString Inherits String
Public Sub New()
MyBase.New()
'custom code here
End Sub
'Custom properties here
'Custom subs and functions here
End Class

Now, what I would like to be able to do is cast from the well known public
class to my new custom subclass. Do something like this:
Dim wellKnown As String
Dim myCustom As MyString

wellKnown = "Some string"
myCustom = wellKnown
'or if the above won't work
myCustom = CType(wellKnown, MyString)

Then if I'm really daring, be able to go back the other way:
wellKnown = myCustom
'or if need be
wellKnown = CType(myCustom, String)

Seems like it should be a simple action for inheritance, but I guess I'm
missing the obvious if so. I know that it means some values may not be
populated, but I'd like to gracefully handle it.

Any help would be greatly appreciated!

TIA,
SMFX
Nov 21 '05 #1
0 1005

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: JustSomeGuy | last post by:
I have two object types ClassA and ClassB class ClassA { public: int data; operator ClassB() { ClassB b; b.data = data + 1; return (b);
4
by: ITnerd | last post by:
In the interest of code re-use, I would like to place some code in a utility class to be used by other classes. The problem is that this code requires the following snippet: for(i=0; i <...
3
by: Kurt | last post by:
i just can't figure out why something im doing is not working correctly.... public interface IInterface { int someProperty { get; set; }
0
by: Kurt Lange | last post by:
no... the array is created dynamically. and no... that defeats the purpose of what im trying todo.. encapsulate all initializing of variables in base class... derive from it... by deriving...
61
by: Ken Allen | last post by:
I am relatively new to .Net, but have been using VB and C/C++ for years. One of the drawbacks with VB6 and earlier was the difficulty in casting a 'record' to a different 'shape' so one could...
0
by: SMFX | last post by:
Okay, this should be a simple thing, but I can't seemto find the right documentation on it. I created a custom class that inherits from a well known class. For example: Class MyString Inherits...
8
by: Michael | last post by:
Hi, I think my problem deals with class casting and inheritance. I want to deal with various Audio Formats, reading into memory for modification, working with it (done by different classes),...
8
by: David Williams | last post by:
Hi all, I have a templated Vector3D class which holds (x,y,z) components as the specified type. I quite often wish to cast a Vector3D holding ints into a Vector3D holding floats and vice versa....
2
by: keithb | last post by:
I'm trying to understand C# type casting. The following code will not compile unless I Cast item to a String. private static String myData; foreach (DataRow row in MyTable.Rows) { foreach...
3
by: Tigger | last post by:
I have an object which could be compared to a DataTable/List which I am trying to genericify. I've spent about a day so far in refactoring and in the process gone through some hoops and hit some...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.