Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> C#

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


Phương thức Uri.CheckSchemeName() trong C# được sử dụng để xác định xem tên lược đồ (scheme name) được chỉ định có hợp lệ hay không.

Cú pháp

Dưới đây là cú pháp:

public static bool CheckSchemeName (string schemeName);

Trong đó, tham số schemeName là tên lược đồ cần xác thực.

Ví dụ 1

Hãy xem ví dụ sau để triển khai phương thức Uri.CheckSchemeName():

using System;
public class Demo {
    public static void Main(){
        Uri newURI = new Uri("https://www.tutorialspoint.com");
        Console.WriteLine("URI = " + newURI);
        string schemeName = newURI.Scheme;
        if(Uri.CheckSchemeName(schemeName))
            Console.WriteLine("Valid: Scheme name");
        else
            Console.WriteLine("Invalid: Scheme name");
    }
}

Đầu ra

Chương trình sẽ cho ra kết quả sau:

URI = https://www.tutorialspoint.com/
Valid: Scheme name

Ví dụ 2

Ví dụ khác triển khai phương thức Uri.CheckSchemeName():

using System;
public class Demo {
    public static void Main(){
        Uri newURI = new Uri("https://www.tutorialspoint.com/index.htm");
        Console.WriteLine("URI = " + newURI);
        string schemeName = newURI.Scheme;
        if(Uri.CheckSchemeName(schemeName))
            Console.WriteLine("Valid: Scheme name");
        else
            Console.WriteLine("Invalid: Scheme name");
    }
}

Đầu ra

Chương trình sẽ cho ra kết quả sau:

URI = https://www.tutorialspoint.com/index.htm
Valid: Scheme name