- 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
C# Numeric Promotion for Conditional Expression
Numeric promotion is the promotion of smaller types to larger types like short to int.
In the below example, we have seen a numeric promotion in Conditional Expression.
The short types are automatically promoted to larger type int.
Example
using System; class Program { static void Main() { short val1 = 99; int val2; val2 = (val1 == 1) ? 100 : 30; Console.WriteLine(val2); } }
Output
Above, we have used a conditional expression that automatically promoted to int −
val2 = (val1 == 1) ? 100 : 30;
Here, val2 is an int and val is a short.
Advertisements