Is there a way to define an implicit conversion operator in VB.NET?

In VB.NET, use the Widening CType operator to create an implicit conversion:

Class C1
    Public Shared Widening Operator CType(ByVal p1 As C1) As C2

    End Operator
End Class

The opposite, an explicit conversion, can be done by swapping Narrowing for Widening in the above definition.

Leave a Comment