Ler em inglês

Compartilhar via


Uri.FromHex(Char) Método

Definição

Obtém o valor decimal de um dígito hexadecimal.

C#
public static int FromHex (char digit);

Parâmetros

digit
Char

Os dígitos hexadecimais (0-9, a-f, A-F) a serem convertidos.

Retornos

Int32

Um número de 0 a 15 que corresponde ao dígito hexadecimal especificado.

Exceções

digit não é um dígito hexadecimal válido (0-9, a-f, A-F).

Exemplos

O exemplo a seguir determina se um caractere é um caractere hexadecimal e, se for, grava o valor decimal correspondente no console.

C#
char  testChar = 'e';
if (Uri.IsHexDigit(testChar) == true)
    Console.WriteLine("'{0}' is the hexadecimal representation of {1}", testChar, Uri.FromHex(testChar));
else
    Console.WriteLine("'{0}' is not a hexadecimal character", testChar);

string returnString = Uri.HexEscape(testChar);
Console.WriteLine("The hexadecimal value of '{0}' is {1}", testChar, returnString);

Comentários

O FromHex método converte um caractere que representa um dígito hexadecimal (0-9, a-f, A-F) em seu valor decimal (0 a 15). Se digit não for um dígito hexadecimal válido, uma exceção ArgumentException será gerada.

Aplica-se a

Produto Versões
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
.NET Standard 2.0, 2.1