Help with User-Defined Types

peterjp80

New member
Joined
Apr 2, 2007
Messages
3
Programming Experience
10+
Hi everyone! I'm usually pretty good at googling to find the information I need, but I am COMPLETELY stuck on this one! Any help would be greatly appreciated.

Here's what I'm trying to accomplish: I want a user-defined type (structure or class) for a phone number in either VB.NET, C++ or C# (preferably VB). I want it to work like most VB.NET types. For example:

Private x As String = "Test"
Private y As Phone = "6315551212"

How can I accomplish this? Any help would be greatly appreciated!
 
(I thought Widening was a conversion from one type to another where the data containing capabilities of the destination, within the context of whichever semantic the developer chooses to apply, exceed the data containing capabilities of the source.

In this case, it is humanly logical to see that a string has the capability to, in some form or another, entirely represent the entire range of values an int can support. This might not be a two way conversion, but in this particular case, logic dictates that it can be. I dont see anything that states an operation cannot be a widening one if it cannot be reversed; the widen surely only applies within the context of the single trip from source->destination)
 
I don't see the framework have defined any custom CType operators for types, it is the CompilerServices.Conversions that handle implicit type conversions. But the conclusion for my above statement (contract) is true for the logic implied with how some implicit conversion are allowed strict and others not. For example int to double is 'allowed', but not the other way around implicitly because not all doubles can be preserved by an integer, but if you strict cast the double back to int you will have lost nothing of original data, so the contract is fulfilled from the no-problem implicit int to double conversion. Go figure it out.
 
Back
Top