Skip to content

Latest commit

 

History

History
48 lines (41 loc) · 2.64 KB

File metadata and controls

48 lines (41 loc) · 2.64 KB
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
devlang-visual-basic
ms.topic article
helpviewer_keywords
procedures [Visual Basic], defining
operators [Visual Basic], defining
procedures [Visual Basic], operator
operators [Visual Basic], overloading
return values [Visual Basic], Operator procedures
operator overloading
ms.assetid 54203dfa-c24b-463f-9942-d5153e89e762
caps.latest.revision 14
author dotnet-bot
ms.author dotnetcontent

How to: Define a Conversion Operator (Visual Basic)

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.

Example

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]

See Also

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