C# 中的强制类型转换运算符 () 是什么?
类型转换是将一种数据类型转换为另一种数据类型。 显式转换由用户使用预定义函数完成,且需要强制类型转换运算符。
下面我们来看一个将 double 类型转换为 int 类型的强制类型转换示例 −
示例
using System;
namespace Demo {
class Program {
static void Main(string[] args) {
double a = 4563.56;
int x;
x = (int)a;
Console.WriteLine(x);
Console.ReadKey();
}
}
}要将 double 类型转换为 int 类型,我们需要执行显式类型转换 −
x = (int)a;
广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程语言
C++
C#
MongoDB
MySQL
JavaScript
PHP