首页  >  文章  >  后端开发  >  C# 中的强制转换运算符 () 是什么?

C# 中的强制转换运算符 () 是什么?

WBOY
WBOY转载
2023-08-31 12:05:021336浏览

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;

以上是C# 中的强制转换运算符 () 是什么?的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文转载于:tutorialspoint.com。如有侵权,请联系admin@php.cn删除