Programming Tutorials

Implicit & explicit type Conversion in VB.net

By: Issac in VB.net Tutorials on 2009-01-30  

In VB.net, there are two types of type conversions: implicit and explicit.

Implicit Type Conversion: Implicit type conversion is a conversion that occurs automatically when one data type is assigned to another data type. In this type of conversion, the data type of the target variable is compatible with the data type of the source variable. For example, assigning an integer to a float data type.

Dim num As Integer = 10
Dim numFloat As Single = num 'implicit type conversion from integer to single

Explicit Type Conversion: Explicit type conversion, also known as type casting, is a conversion that occurs when the data type of the source variable is not compatible with the data type of the target variable. In this type of conversion, the programmer has to explicitly convert the data type of the source variable to the data type of the target variable. For example, converting a string to an integer data type.

Dim str As String = "10"
Dim num As Integer = CInt(str) 'explicit type conversion from string to integer

In the above example, the CInt function is used to convert the string data type to the integer data type explicitly.






Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in VB.net )

Latest Articles (in VB.net)