Uri.IsHexDigit() Method in C#


The Uri.IsHexDigit() method in C# determines whether a specified character is a valid hexadecimal digit.

Syntax

Following is the syntax −

public static bool IsHexDigit (char ch);

Above, the parameter ch is the character to validate.

Example

Let us now see an example to implement the Uri.IsHexDigit() method −

using System;
public class Demo {
   public static void Main(){
      char ch = 'e';
      Console.WriteLine("Character value = "+ch);
      int res = Uri.FromHex(ch);
      Console.WriteLine("Converted int value = "+res);
      if(Uri.IsHexDigit(ch)) {
         Console.WriteLine("Valid hexadecimal digit");
      } else {
         Console.WriteLine("Invalid hexadecimal digit");
      }
   }
}

Output

This will produce the following output −

Character value = e
Converted int value = 14
Valid hexadecimal digit

Example

Let us now see another example to implement the Uri.IsHexDigit() method −

using System;
public class Demo {
   public static void Main(){
      char ch = '#';
      Console.WriteLine("Character value = "+ch);
      if(Uri.IsHexDigit(ch)) {
         Console.WriteLine("Valid hexadecimal digit");
      } else {
         Console.WriteLine("Invalid hexadecimal digit");
      }
   }
}

Output

This will produce the following output −

Character value = #
Invalid hexadecimal digit

Updated on: 14-Nov-2019

52 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements