Uri.IsHexDigit(Char)方法用於確定指定字符是否為有效的十六進製數字。十六進製數字是數字0到9,以及字母A-F或a-f。
用法: public static bool IsHexDigit (char character);
Here, it takes the character to validate.
返回值:如果字符是有效的十六進製數字,則此方法返回true,否則返回false。
以下示例程序旨在說明Uri.IsHexDigit(Char)方法的用法:
示例1:
// C# program to demonstrate the
// Uri.IsHexDigit(Char) Method
using System;
using System.Globalization;
class GFG {
// Main Method
public static void Main()
{
// Declaring and initializing address1
char ch = 'a';
// Validating the Character
// using IsHexDigit(Char) method
bool value = Uri.IsHexDigit(ch);
// Displaying the result
if (value)
Console.WriteLine("{0} is a valid Hexadecimal Digit", ch);
else
Console.WriteLine("{0} is a not valid Hexadecimal Digit", ch);
}
}
輸出:
a is a valid Hexadecimal Digit
示例2:
// C# program to demonstrate the
// Uri.IsHexDigit(Char) Method
using System;
using System.Globalization;
class GFG {
// Main Method
public static void Main()
{
// calling get() method
get('a');
get('.');
get('1');
}
// defining get() method
public static void get(char ch)
{
// Validating the Character
// using IsHexDigit(Char) method
bool value = Uri.IsHexDigit(ch);
// Displaying the result
if (value)
Console.WriteLine("{0} is a valid Hexadecimal Digit", ch);
else
Console.WriteLine("{0} is a not valid Hexadecimal Digit", ch);
}
}
輸出:
a is a valid Hexadecimal Digit . is a not valid Hexadecimal Digit 1 is a valid Hexadecimal Digit
參考:
相關用法
- C# DateTimeOffset.Add()用法及代碼示例
- C# String.Contains()用法及代碼示例
- C# Math.Sin()用法及代碼示例
- C# Math.Cos()用法及代碼示例
- C# Dictionary.Add()用法及代碼示例
- C# Math.Tan()用法及代碼示例
- C# Math.Abs()方法用法及代碼示例
- C# Math.Exp()用法及代碼示例
- C# Math.Abs()函數用法及代碼示例
注:本文由純淨天空篩選整理自RohitPrasad3大神的英文原創作品 C# | Uri.IsHexDigit() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。