Uri.ToString() 方法在 C# 中
C# 中的 Uri.ToString() 方法用于获取指定 Uri 实例的规范字符串表示形式。
语法
以下是语法 −
public override string ToString ();
示例
现在让我们看一个示例来实现 Uri.ToString() 方法 −
using System;
public class Demo {
public static void Main(){
Uri newURI1 = new Uri("https://tutorialspoint.com/");
Console.WriteLine("URI = "+newURI1);
Console.WriteLine("String representation = "+newURI1.ToString());
Uri newURI2 = new Uri("https://tutorialspoint.com/jquery.htm#abcd");
Console.WriteLine("
URI = "+newURI2);
Console.WriteLine("String representation = "+newURI2.ToString());
if(newURI1.Equals(newURI2))
Console.WriteLine("
Both the URIs are equal!");
else
Console.WriteLine("
Both the URIs aren't equal!");
Uri res = newURI1.MakeRelativeUri(newURI2);
Console.WriteLine("Relative uri = "+res);
}
}输出
这将产生以下输出 −
URI = https://tutorialspoint.com/ String representation = https://tutorialspoint.com/ URI = https://tutorialspoint.com/jquery.htm#abcd String representation = https://tutorialspoint.com/jquery.htm#abcd Both the URIs aren't equal! Relative uri = jquery.htm#abcd
广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 语言编程
C++
C#
MongoDB
MySQL
JavaScript
PHP