Overloading CType

The CType operator also can be overloaded to provide appropriate mechanisms for converting to and from a custom type. The interesting thing in overloading CType is that you have to consider both situations studied in Chapter 4, known as widening and narrowing conversions (see that topic for further details). Continuing the previous example of the ThreePoint structure, the following code snippet offers a special implementation of CType enabling conversions to and from an array of integers:

image

The code is quite simple. Notice how you must specify a keyword corresponding to the effective kind of conversion (Widening and Narrowing

Get Visual Basic® 2010 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.