- 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 are implicit type conversions in C#?
Type conversions in C# has both implicit as well as explicit type conversions. Under Implicit, the conversions are 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.
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 shown an error. Since the compiler does 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 =11000; int val2 =35600; long sum; sum = val1 + val2; Console.WriteLine("Sum= " + sum); Console.ReadLine(); } } }
Output
Sum= 46600
Advertisements