| title | How to: Define a Conversion Operator (Visual Basic) | ||||||
|---|---|---|---|---|---|---|---|
| ms.custom | |||||||
| ms.date | 07/20/2015 | ||||||
| ms.prod | .net | ||||||
| ms.reviewer | |||||||
| ms.suite | |||||||
| ms.technology |
|
||||||
| ms.topic | article | ||||||
| helpviewer_keywords |
|
||||||
| ms.assetid | 54203dfa-c24b-463f-9942-d5153e89e762 | ||||||
| caps.latest.revision | 14 | ||||||
| author | dotnet-bot | ||||||
| ms.author | dotnetcontent |
If you have defined a class or structure, you can define a type conversion operator between the type of your class or structure and another data type (such as Integer, Double, or String).
Define the type conversion as a CType Function procedure within the class or structure. All conversion procedures must be Public Shared, and each one must specify either Widening or Narrowing.
Defining an operator on a class or structure is also called overloading the operator.
The following example defines conversion operators between a structure called digit and a Byte.
[!code-vbVbVbcnProcedures#27]
You can test the structure digit with the following code.
[!code-vbVbVbcnProcedures#28]
Operator Procedures
How to: Define an Operator
How to: Call an Operator Procedure
How to: Use a Class that Defines Operators
Operator Statement
Structure Statement
How to: Declare a Structure
Implicit and Explicit Conversions
Widening and Narrowing Conversions