You are on page 1of 3
rier207 How to: Convert an Object to Another Type in Visual Basic | Microsoft Doos How to: Convert an Object to Another Type in Visual Basic 7/29/2017 » 1 min to read + Contributors + @@ In this article Example Compiling the Code See Also You convert an object variable to another data type by using a conversion keyword such as CType Function. Example The following example converts an object variable to an. Integer anda. string Copy Public Sub objectConversion(ByVal anObject As Object) Dim anInteger As Integer Dim aString As String anInteger = CType(anObject, Integer) aString = CType(anobject, String) End Sub If you know that the contents of an. object variable are of a particular data type, it is better to convert the variable to that data type. If you continue to use the object variable, you incur either boxing and unboxing (for a value type) or late binding (for a reference type). These operations all take extra execution time and make your performance slower. Compiling the Code This example requires: * Areference to the System namespace. See Also hitps:ifdocs,microsoft com/en-usidoinetisual-basicprogramming-quidelanguage-featuresidata-ypesmhow-to-convertan-objeckic-ancther‘ype 1/9. nei2017 How to: Convert an Object to Ancthr Type in Visual Basic | Microsoft Doos Object Type Conversions in Visual Basic Widening and Narrowing Conversions Implicit and Explicit Conversions Conversions Between Strings and Other Types Array Conversions Structures Data Types Type Conversion Functions hitps:iidocs.microsoflcom/en-usidotnetisual-basilprogramming-quidelanguage- turesdate-typesthowo-convertan-abjecttc-anather‘ype 2/8, rier207 How to: Convert an Object to Another Type in Visual Basic | Microsoft Doos hitps:ifdocs,microsofl com/en-usidoinetisual-basicprogramming-quidelanguage-featuresidata-ypesmhow-to-convertan-objeckic-ancther‘ype 3/9

You might also like