Computer >> Máy Tính >  >> Lập trình >> C#

Phương thức Uri.IsHexDigit () trong C #

Phương thức Uri.IsHexDigit () trong C # xác định xem một ký tự được chỉ định có phải là một chữ số thập lục phân hợp lệ hay không.

Cú pháp

Sau đây là cú pháp -

public static bool IsHexDigit (char ch);

Ở trên, tham số ch là ký tự để xác thực.

Ví dụ

Bây giờ chúng ta hãy xem một ví dụ để triển khai phương thức Uri.IsHexDigit () -

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

Đầu ra

Điều này sẽ tạo ra kết quả sau -

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

Ví dụ

Bây giờ chúng ta hãy xem một ví dụ khác để triển khai phương thức Uri.IsHexDigit () -

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

Đầu ra

Điều này sẽ tạo ra kết quả sau -

Character value = #
Invalid hexadecimal digit