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

Toán tử Cast () trong C#


Chuyển kiểu tường minh (explicit conversion) cần cast operator.

Ví dụ cast double -> int:

Ví dụ

using System;
namespace Demo {
    class Program {
        static void Main(string[] args) {
            double a = 4563.56;
            int x = (int)a;
            Console.WriteLine(x);
            Console.ReadKey();
        }
    }
}

Ép kiểu: x = (int)a;