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.
Step 2
Create a NULL string variable. The string is 2 bytes.
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.
- str=Convert.toString(Val);
Step 4
Above code output will be:
Step 5
If you want to convert to another format, for example, string to int, int to float, float to string etc.
-
- int temp=Convert.Int32(str);
-
- 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.
- int a=123;
- String str=Convert.toString(a);
- output
- "123"
Char to Integer
In the below code conversion from string to integer.
- string str="1234";
- int val=Convert.toInt32(str);
- output
- 1234
Integer to Float
The below code shows Integer to float data type conversion.
- int a=12;
- float val=Convert.ToSingle(a);
- output
- 12.00
Int to Double
The below code is int to double data type conversion.
- int val=54;
- Double d=Convert.ToDouble(val);
- output
- 54.00
Float to Double
The below code is float to double data type conversion.
- float f=1.5f;
- Double val=Convert.ToDouble(f);
- output
- 1.500