C# | Uri.IsHexDigit() Method
Last Updated :
30 Apr, 2019
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:
using System;
using System.Globalization;
class GFG {
public static void Main()
{
char ch = 'a' ;
bool value = Uri.IsHexDigit(ch);
if (value)
Console.WriteLine( "{0} is a valid Hexadecimal Digit" , ch);
else
Console.WriteLine( "{0} is a not valid Hexadecimal Digit" , ch);
}
}
|
Output:
a is a valid Hexadecimal Digit
Example 2:
using System;
using System.Globalization;
class GFG {
public static void Main()
{
get ( 'a' );
get ( '.' );
get ( '1' );
}
public static void get ( char ch)
{
bool value = Uri.IsHexDigit(ch);
if (value)
Console.WriteLine( "{0} is a valid Hexadecimal Digit" , ch);
else
Console.WriteLine( "{0} is a not valid Hexadecimal Digit" , ch);
}
}
|
Output:
a is a valid Hexadecimal Digit
. is a not valid Hexadecimal Digit
1 is a valid Hexadecimal Digit
Reference:
Share your thoughts in the comments
Please Login to comment...