Home > Article > Backend Development > C# Numeric promotion of conditional expressions
Numerical promotion is to promote a smaller type to a larger type, such as from short to int.
In the example below, we see numeric boosting in the conditional expression.
p>
Short types are automatically promoted to larger int types.
using System; class Program { static void Main() { short val1 = 99; int val2; val2 = (val1 == 1) ? 100 : 30; Console.WriteLine(val2); } }
Above, we used a conditional expression that is automatically promoted to int -
val2 = (val1 == 1) ? 100 : 30;
Here, val2 is an int, val is a short.
The above is the detailed content of C# Numeric promotion of conditional expressions. For more information, please follow other related articles on the PHP Chinese website!