Uri.FromHex(Char) Metod
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Hämtar decimalvärdet för en hexadecimal siffra.
public:
static int FromHex(char digit);
public static int FromHex(char digit);
static member FromHex : char -> int
Public Shared Function FromHex (digit As Char) As Integer
Parametrar
- digit
- Char
Hexadecimal siffra (0-9, a-f, A-F) att konvertera.
Returer
Ett tal från 0 till 15 som motsvarar den angivna hexadecimala siffran.
Undantag
digit är inte en giltig hexadecimal siffra (0-9, a-f, A-F).
Exempel
I följande exempel avgörs om ett tecken är ett hexadecimalt tecken och, om det är det, skriver motsvarande decimalvärde till konsolen.
char testChar = 'e';
if (Uri.IsHexDigit(testChar))
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);
let testChar = 'e'
if Uri.IsHexDigit testChar then
printfn $"'{testChar}' is the hexadecimal representation of {Uri.FromHex testChar}"
else
printfn $"'{testChar}' is not a hexadecimal character"
let returnString = Uri.HexEscape testChar
printfn $"The hexadecimal value of '{testChar}' is {returnString}"
Dim testChar As Char = "e"c
If Uri.IsHexDigit(testChar) = True Then
Console.WriteLine("'{0}' is the hexadecimal representation of {1}", testChar, Uri.FromHex(testChar))
Else
Console.WriteLine("'{0}' is not a hexadecimal character", testChar)
End If
Dim returnString As String = Uri.HexEscape(testChar)
Console.WriteLine("The hexadecimal value of '{0}' is {1}", testChar, returnString)
Kommentarer
Metoden FromHex konverterar ett tecken som representerar en hexadecimal siffra (0-9, a-f, A-F) till dess decimalvärde (0 till 15). Om digit inte är en giltig hexadecimal siffra genereras ett ArgumentException undantag.