当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


C# Uri.IsHexDigit()用法及代码示例


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

参考:



相关用法


注:本文由纯净天空筛选整理自RohitPrasad3大神的英文原创作品 C# | Uri.IsHexDigit() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。