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);
}
}
ผลลัพธ์
Implicit conversion from 16-bit unsigned integer to Decimal
Decimal = 2567