C# | Uri.IsHexDigit() Method

Uri.IsHexDigit(Char) Method is used to determine whether a specified character is a valid hexadecimal digit or not. Hexadecimal digits are the digits 0 to 9 and the letters A-F or a-f.

Syntax: public static bool IsHexDigit (char character);
Here, it takes the character to validate.

Return Value: This method returns true if the character is a valid hexadecimal digit otherwise, false.

Below programs illustrate the use of Uri.IsHexDigit(Char) Method:

Example 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

// 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);
    }
}

chevron_right


Output:

a is a valid Hexadecimal Digit

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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);
    }
}

chevron_right


Output:

a is a valid Hexadecimal Digit
. is a not valid Hexadecimal Digit
1 is a valid Hexadecimal Digit

Reference:



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.