Home  >  Article  >  Backend Development  >  C# Numeric promotion of conditional expressions

C# Numeric promotion of conditional expressions

王林
王林forward
2023-09-08 09:25:08746browse

C# 条件表达式的数字提升

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.

Example

using System;

class Program {
   static void Main() {
      short val1 = 99;
      int val2;

      val2 = (val1 == 1) ? 100 : 30;

      Console.WriteLine(val2);
   }
}

Output

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete