DataType Convertion In C#.net


To Convert the Base Data Type To an other Base Data Type,we use “Convert” class and its functions the target Data Type,Check the below example


int i;
 for (i = 0; i < 5; i++)
 {
 MessageBox.Show(Convert.ToString(i), "Integer To String", MessageBoxButtons.OK, MessageBoxIcon.Information);
 }

Description

we use one integer type variable “i”.and use “for” loop to increment the value of “i” and display the message box.

Convert.ToString(i),is responsible to convert the integer value to string, and message box is only show the string value so i use the Convert.ToString(i) inside the message box.

The above Example is convert the base data type Integer to other base data type String.

It is not only convert the integer data type to string, but its able to convert any base data type to other base data type.

Advertisements