- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is Type conversion in C#?
To convert one datatype to another in C#, use Type Conversion. In C#, the type conversions are of two types −
Implicit type conversion
Performed by C# in a type-safe manner. For example, are conversions from smaller to larger integral types and conversions from derived classes to base classes.
Explicit type conversion
Performed explicitly by users using the pre-defined functions. Explicit conversions require a cast operator.
Let us see an example to cast double to int i.e. explicit type conversion −
Example
using System; namespace Demo { class Program { static void Main(string[] args) { double d = 8745.97; int x; x = (int)d; Console.WriteLine(x); Console.ReadKey(); } } }
Output
8745
Advertisements