VB.Net-Informations.com
   Home      .Net Framework      VB.NET      C#                                                                      About


  VB.NET Implicit and Explicit Conversions

Implicit Type Conversions

Implicit Conversion perform automatically in VB.NET, that is the compiler is taking care of the conversion.

The following example you can see how it happen.

1. Dim iDbl As Double

2. Dim iInt As Integer

3. iDbl = 9.123

4. MsgBox("The value of iDbl is " iDbl)

5. iInt = iDbl

6. MsgBox("The value of iInt is " iInt)

line no 1 : Declare a Double datatype variable iDble

line no 2 : Declare an Integer datatyoe variable iInt

line no 3 : Assign a decimal value to iDbl

line no 4 : Display the value of iDbl

line no 5 : Assign the value of iDbl to iInt

line no 6 : Display the value of iInt

The first messagebox display the value of iDbl is 9.123

The second messegebox display the value od iInt is 9

iInt display only 9 because the value is narrowed to 9 to fit in an Integer variable.

Here the Compiler made the conversion for us. These type fo conversions are called Implicit Conversion .

The Implicit Conversion perform only when the Option Strict switch is OFF

         VB.NET Source Code Download           Print Source Code
         VB.NET Implicit and Explicit Conversions - Download
        
C# Tutorial

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click
        Dim iDbl As Double
        Dim iInt As Integer
        iDbl = 9.123
        MsgBox("The value of iDbl is " & iDbl)
        iInt = iDbl
        'after conversion
        MsgBox("The value of iInt is " & iInt)
    End Sub
End Class

Explicit Type Conversions
In some cases we have to perform conversions , that is the compiler does not automatically convert a type to another . These type of conversion is called Explicit conversion . An explicit conversion uses a type conversion keyword. With these conversion keywords we hav to perform the Explicit Conversion.



VB.NET Language Basics Related Contents
*     VB.NET data types
*     VB.NET Access Specifiers
*     VB.NET Exceptions
*     VB.NET Option Explicit
*     VB.NET Option Strict
*     VB.NET On Error


   Home      VB.NET      C#
VB.Net Related Topics
*     Microsoft .Net Framework Tutorials
*     VB.NET Language Basics Tutorials
*     VB.NET Program Flow Control Tutorials
*     VB.NET Collections Tutorials
*     VB.NET String Tutorials
*     VB.NET Files Tutorials
*     VB.NET Excel 2007 Tutorials
*     VB.NET Crystal Reports Tutorials
*     VB.NET Communications Tutorial
*     VB.NET ADO.NET Tutorial
*     ADO.NET Data Providers help and Tutorial
*     VB.NET ADO.NET Dataset Tutorial
*     ADO.NET DataAdapter and Dataset
*     VB.NET ADO.NET DataView Tutorial
*     VB.NET Remoting Tutorial
*     VB.NET XML Tutorial
*     VB.NET DataGridView Tutorial
   Home      VB.NET      C#
More Source Code :   
Mail to :  feedback@net-informations.com
  |  Home   |  VB.NET   |  C#   |  SiteMap   |  Terms of Use   |  About   |
net-informations.com (C) 2010
All Rights Reserved. All other trademarks are property of their respective owners.