เมธอด Uri.FromHex() ใน C# ใช้สำหรับดึงค่าทศนิยมของตัวเลขฐานสิบหก (hexadecimal digit)
ไวยากรณ์
ไวยากรณ์มีดังนี้:
public static int FromHex (char digit);
พารามิเตอร์ digit คือตัวเลขฐานสิบหก (0-9, a-f, A-F) ที่ต้องการแปลง
ตัวอย่าง
ตัวอย่างการแปลง 'D':
using System;
public class Demo {
public static void Main(){
char ch = 'D';
Console.WriteLine("Character value = " + ch);
int res = Uri.FromHex(ch);
Console.WriteLine("Converted int value = " + res);
}
}
ผลลัพธ์
โค้ดจะแสดงผลดังนี้:
Character value = D Result = 13
ตัวอย่างเพิ่มเติม
ตัวอย่างการแปลง '6':
using System;
public class Demo {
public static void Main(){
char ch = '6';
Console.WriteLine("Character value = " + ch);
int res = Uri.FromHex(ch);
Console.WriteLine("Result = " + res);
}
}
ผลลัพธ์
โค้ดจะแสดงผลดังนี้:
Character value = 6 Result = 6