Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C#

การแปลงนัยโดยนัยจากจำนวนเต็ม 8 บิต มีเครื่องหมาย (SByte) เป็น Decimal ใน C#

SByte แทนจำนวนเต็ม 8 บิต ที่มีเครื่องหมาย

เพื่อแปลงนัยโดยนัยของจำนวนเต็ม 8 บิต มีเครื่องหมาย เป็น Decimal ขั้นแรกให้กำหนดค่า sbyte:

sbyte val = 51;

เพื่อแปลง sbyte เป็น decimal ให้กำหนดค่า:

decimal d; d = val;

มาดูตัวอย่างอีกตัวหนึ่ง

ตัวอย่าง

using System;

public class Demo
{
    public static void Main()
    {
        sbyte val = 39;
        decimal d;
        Console.WriteLine("Implicit conversion from 8-bit signed integer (sbyte) to Decimal");
        d = val;
        Console.WriteLine("Decimal = " + dec);
    }
}

ผลลัพธ์

Implicit conversion from 8-bit signed integer (sbyte) to Decimal
Decimal = 39