C# 中的 Uri.IsWellFormedOriginalString() 方法

csharpserver side programmingprogramming更新于 2025/9/23 10:37:17

C# 中的 Uri.IsWellFormedOriginalString() 方法用于指示用于构造此 Uri 的字符串是否格式正确,且无需进一步转义。

语法

以下是语法 −

public bool IsWellFormedOriginalString ();

示例

现在让我们看一个实现 Uri.IsWellFormedOriginalString() 方法的示例−

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("Both the URIs are equal!");
      else
         Console.WriteLine("Both the URIs aren't equal!");
      if(newURI1.IsWellFormedOriginalString())
         Console.WriteLine("newURI1 is well formed!");
      else
         Console.WriteLine("newURI1 isn't well formed!");
   }
}

输出

这将产生以下输出 −

URI = https://www.tutorialspoint.com/index.htm
URI = https://www.tutorialspoint.com/
Both the URIs aren't equal!
newURI1 is well formed!

相关文章