
- 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 the difference between implicit and explicit type conversion in C#?
The following is the difference between implicit and explicit type conversion −
Implicit Type Conversion
These conversions are performed by C# in a type-safe manner.
To understand the concept, let us implicitly convert int to long.
int val1 = 11000; int val2 = 35600; long sum; sum = val1 + val2;
Above, we have two integer variable and when we sum it in a long variable, it won’t show an error. Since the compiler does the implicit conversion on its own.
Let us print the values now.
Example
using System; using System.IO; namespace Demo { class Program { static void Main(string[] args) { int val1 =34567; int val2 =56743; long sum; sum = val1 + val2; Console.WriteLine("Sum= " + sum); Console.ReadLine(); } } }
Explicit Type Conversion
These conversions are done explicitly by users using the pre-defined functions.
Let us see an example to typecast double to int −
Example
using System; namespace Program { class Demo { static void Main(string[] args) { double d = 1234.89; int i; // cast double to int. i = (int)d; Console.WriteLine(i); Console.ReadKey(); } } }
- Related Articles
- What are implicit and explicit type conversions in C language?
- What is the difference between type conversion and type casting in C#?
- Difference Between Type casting and Type Conversion
- What are the differences between implicit and explicit waits in Selenium with python?
- What are the differences between Widening Casting (Implicit) and Narrowing Casting (Explicit) in Java?
- What is Type Conversion?
- Difference between Tacit Knowledge and Explicit Knowledge
- What is Type conversion in C#?
- What is type conversion in java?
- What is the difference between dynamic type variables and object type variables?
- What are explicit type conversions in C#?
- How does Implicit coercion differ from Explicit coercion in JavaScript?
- What are implicit type conversions in C#?
- Implicit conversion from Int16 to Decimal in C#
- Implicit conversion from Char to Decimal in C#

Advertisements