Home > Backend Development > C#.Net Tutorial > C# Numeric promotion of conditional expressions

C# Numeric promotion of conditional expressions

王林
Release: 2023-09-08 09:25:08
forward
805 people have browsed it

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);
   }
}
Copy after login

Output

Above, we used a conditional expression that is automatically promoted to int -

val2 = (val1 == 1) ? 100 : 30;
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template