Lire en anglais

Partager via


Uri.FromHex(Char) Méthode

Définition

Obtient la valeur décimale d'un chiffre hexadécimal.

C#
public static int FromHex (char digit);

Paramètres

digit
Char

Chiffre hexadécimal (0-9, a-f, A-F) à convertir.

Retours

Int32

Nombre compris entre 0 et 15 qui correspond au chiffre hexadécimal spécifié.

Exceptions

digit n'est pas un chiffre hexadécimal valide (0-9, a-f, A-F).

Exemples

L’exemple suivant détermine si un caractère est un caractère hexadécimal et, le cas échéant, écrit la valeur décimale correspondante dans la 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);

Remarques

La FromHex méthode convertit un caractère représentant un chiffre hexadécimal (0-9, a-f, A-F) en sa valeur décimale (0 à 15). Si digit ce n’est pas un chiffre hexadécimal valide, une ArgumentException exception est levée.

S’applique à

Produit Versions
.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