Data Type conversion in C# tutorials
Converting one datatype into another datatype is called type conversion. It is also called as Type Casting. In C#, it is of 2 kinds
Implicit type conversion – It is performed by C# compiler in a type-safe manner.
e.g. Converting from smallest to largest integral types and conversions from derived to base classes.
Explicit type conversion – It is handled explicitly by the users using the type conversion methods. It requires a type cast operator.
The following code represents explicit type conversion
Data Type conversion in C# Assignment Help By Online Tutoring and Guided Sessions from assignmenthippo.com
Type Conversion Methods in C#
Method |
Description |
ToBoolean |
Converts a type to Boolean value |
ToByte | Converts a type to byte. |
ToChar |
Converts a type to single Unicode character |
ToDateTime | Converts a integer type or string type to date-time structures. |
ToDecimal | Converts a floating point type or integer type to decimal type. |
ToDouble | Converts a type to double type. |
ToInt16 |
Converts a type to 16-bit integer. |
ToInt32 |
Converts a type to 32-bit integer. |
ToInt64 |
Converts a type to 64-bit integer. |
ToSbyte | Converts a type to signed byte type. |
ToSingle | Converts a type to small floating point number. |
ToString | Converts a type to string. |
ToType | Converts a type to specified type. |
ToUInt16 | Converts a type to an unsigned int type. |
ToUInt32 | Converts a type to an unsigned long type. |
ToUInt64 | Converts a type to an unsigned big integer. |