隱式從 16 位無符號整數(ushort)轉換為 C# 中的 Decimal


UShort 表示一個 16 位無符號整數。

要將一個 16 位無符號整數隱式轉換為一個 Decimal,首先設定一個 ushort 值。

ushort val = 193;

要將 ushort 轉換為 Decimal,分配該值。

decimal dec;
dec = val;

我們來看一個例子。

示例

using System;
public class Demo {
   public static void Main() {
      ushort val = 2567;
      decimal dec;
      Console.WriteLine("Implicit conversion from 16-bit unsigned integer to Decimal");
      dec = val;
      Console.WriteLine("Decimal = "+dec);
   }
}

更新時間:2020-06-23

347 次瀏覽

開啟你的 職業生涯

完成課程獲得認證

開始學習
廣告
© . All rights reserved.