Data Type Conversion In C#

If you want data conversion in C#.net to follow the below steps. 
 
Step 1
 
Create an integer variable and assign integer value. Integer size is 4 bytes. 
  1. int val=1235;  
Step 2
 
Create a NULL string variable. The string is 2 bytes.
  1. string str="";  
Step 3
 
If I want to convert the integer to string we have to use this inbuilt function Convert.ToString(Parameter) and store this value as a string variable.
  1. str=Convert.toString(Val);  
Step 4
 
Above code output will be:
  1. str="1235"  
Step 5 
 
If you want to convert to another format, for example, string to int, int to float, float to string etc. 
  1. //int32 and int16 this are used for 16 bit and 32 bit.  
  2. int temp=Convert.Int32(str);  
  3. //or  
  4. int temp=Convert.Int16(str);  
If you want to convert data in another format then you can use Convert.toInt32().
 
Integer to char
 
In the below code we see conversion from integer to String.
  1. int a=123;  
  2. String str=Convert.toString(a);  
  3. output
  4. "123"
Char to Integer
 
In the below code conversion from string to integer. 
  1. string str="1234";  
  2. int val=Convert.toInt32(str);  
  3. output
  4. 1234
Integer to Float
 
The below code shows Integer to float data type conversion. 
  1. int a=12;  
  2. float val=Convert.ToSingle(a);  
  3. output
  4. 12.00
Int to Double
 
The below code is int to double data type conversion. 
  1. int val=54;  
  2. Double d=Convert.ToDouble(val);  
  3. output
  4. 54.00
Float to Double
 
The  below code is  float to double data type conversion. 
  1. float f=1.5f;  
  2. Double val=Convert.ToDouble(f);  
  3. output
  4. 1.500