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

การแปลงนัยโดยนัยจาก Char เป็น Decimal ใน C#

เพื่อแปลงนัยโดยนัย char เป็น Decimal ขั้นแรกให้กำหนด char:

char c = 'p';

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

decimal dec; dec = c;

มาดูตัวอย่างข้างต้น

ตัวอย่าง

using System;

public class Demo
{
    public static void Main()
    {
        char c = 'p';
        decimal dec;
        Console.WriteLine("Implicit conversion from Char to Decimal");
        dec = c;
        Console.WriteLine("Decimal : " + dec);
    }
}

ผลลัพธ์

Implicit conversion from Char to Decimal
Decimal : 112