VB.NET-INFORMATIONS.COM



VB.NET Language Basics Tutorials

VB.NET Implicit and Explicit Conversions

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


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

VB.NET Related Tpoics
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 with source code
ADO.NET Data Providers help and Tutorial
VB.NET ADO.NET Dataset Tutorial
ADO.NET DataAdapter and Dataset
VB.NET ADO.NET DataView Tutorial

Search here for more Vb.Net Source Code :


   Categories

    HOME
    VB.NET

 
 
 
   













  |  Home   |  SiteMap   |  About   |
net-informations.com (C) 2008 All Rights Reserved