📜  C#| Uri.IsHexDigit()方法

📅  最后修改于: 2021-05-29 23:42:35             🧑  作者: Mango

Uri.IsHexDigit(Char)方法用于确定指定字符是否为有效的十六进制数字。十六进制数字是数字0到9以及字母AFaf

下面的程序说明了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

参考:

  • https://docs.microsoft.com/zh-cn/dotnet/api/system.uri.ishexdigit?view=netstandard-2.1