
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
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
- Related Articles
- What is Type Conversion?
- What is type conversion in java?
- What is the difference between type conversion and type casting in C#?
- Type Conversion in Python
- Type Conversion in C++
- Data Type Conversion in Python
- What is the difference between implicit and explicit type conversion in C#?
- What is the importance of '+' operator in type conversion in JavaScript?
- What is the type conversion operator ( ) in Java and how to use it?
- Difference Between Type casting and Type Conversion
- Catch block and type conversion in C++
- What is Analog to Digital Conversion?
- How to implement integer type conversion in JShell in Java 9?
- What is Analog to Analog Conversion (Modulation)?
- What is type deduction in C++?

Advertisements