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

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

Phương thức Uri.IsWellFormedOriginalString() trong C# cho biết xem chuỗi dùng để xây dựng Uri này có đúng định dạng và không cần escape thêm hay không.

Cú pháp

public bool IsWellFormedOriginalString ();

Ví dụ

using System; 
public class Demo { 
    public static void Main(){ 
        Uri newURI1 = new Uri("https://www.tutorialspoint.com/index.htm"); 
        Console.WriteLine("URI = " + newURI1); 
        Uri newURI2 = new Uri("https://www.qries.com/"); 
        Console.WriteLine("URI = " + newURI2); 
        if(newURI1.Equals(newURI2)) 
            Console.WriteLine("Hai URI bằng nhau!"); 
        else 
            Console.WriteLine("Hai URI không bằng nhau!"); 
        if(newURI1.IsWellFormedOriginalString()) 
            Console.WriteLine("newURI1 đúng định dạng!"); 
        else 
            Console.WriteLine("newURI1 không đúng định dạng!"); 
    } 
}

Kết quả

URI = https://www.tutorialspoint.com/index.htm 
URI = https://www.tutorialspoint.com/ 
Hai URI không bằng nhau! 
newURI1 đúng định dạng!