Name
CType Function
Named Arguments
No
Syntax
CType(expression, typename)-
expression Use: Required
Data Type: Any
The data item to be converted
-
typename Use: Required
Type: Keyword
The data type, object type, structure, or interface to which
expressionis to be converted
Return Value
expression cast as a
typename interface, object, structure, or
data type.
Description
Converts any expression that can be interpreted as an object to Object.
Rules at a Glance
expressioncan be any data, object, structure, or interface type.typenamecan be any data type (such asBoolean,Byte,Decimal,Long,Short,String, etc.), structure type, object type, or interface that can be used with theAsclause in aDimstatement.If the function fails, or if the converted value of
expressionis outside the range allowed bytypename, an InvalidCastException exception occurs.
Example
Option Strict On Imports Microsoft.VisualBasic Imports System Interface IEmployee Property Name( ) As String Property Salary( ) As Decimal End Interface Public Class CSalaried Implements IEmployee Dim sName As String Dim decSalary AS DEcimal Public Property Name( ) As String Implements IEmployee.Name Get Name = sName End Get Set sName = Value End Set End Property Public Property Salary( ) As Decimal Implements IEmployee.Salary Get Salary = decSalary End Get Set decSalary = Value End Set End Property End Class Module modMain Public Sub Main( ) Dim oSal As New CSalaried Dim oSal2 As CSalaried Dim oEmp As IEmployee oSal.Name = "John Doe" ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access