首頁  >  文章  >  後端開發  >  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刪除