Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> C#

Numeric Promotion (Thăng cấp kiểu số) trong C#


Numeric promotion: kiểu nhỏ tự động promote sang kiểu lớn (short -> int).

Ví dụ nhân short * ushort promote thành int:

Ví dụ

using System;
class Program {
    static void Main() {
        short val1 = 99;
        ushort val2 = 11;
        int res = val1 * val2;
        Console.WriteLine(res);
    }
}