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

前端 未结 1 1113
误落风尘
误落风尘 2020-12-03 16:51

In C#, you can use the implicit keyword to define an implicit user-defined type conversion operator.

In VB.NET, you can define a CType conversion operator that will e

相关标签:
1条回答
  • 2020-12-03 17:32

    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.

    0 讨论(0)
提交回复
热议问题