Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> C#

Phương thức Uri.FromHex() trong C#

Phương thức Uri.FromHex() trong C# được dùng để lấy giá trị thập phân của một chữ số thập lục phân.

Cú pháp

Cú pháp như sau:

public static int FromHex(char digit);

Tham số digit là chữ số thập lục phân (0-9, a-f, A-F) cần chuyển đổi.

Ví dụ 1 - Chuyển đổi '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);
    }
}

Kết quả

Character value = D
Result = 13

Ví dụ 2 - Chuyển đổi '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);
    }
}

Kết quả

Character value = 6
Result = 6