C#| Uri.Equals()方法与示例
Uri.Equals()方法
Uri.Equals()方法是一个覆盖方法,用于检查与当前对象的指定引用是否相等。如果两者相等,则返回true,否则返回false。
语法:
bool Uri.Equals(Uri obj);
Parameter(s):
Uriobj–表示要与当前对象检查的指定对象。
返回值:
此方法的返回类型为Boolean,如果指定的对象或引用等于当前对象,则返回布尔值,然后返回true,否则返回false。
举例说明方法的例子Uri.Equals()
using System; class UriExample { //程序入口 static public void Main() { Uri domainUri1; Uri domainUri2; Uri domainUri3; domainUri1 = new Uri("https://www.nhooo.com/index.html"); domainUri2 = new Uri("https://www.nhooo.com/index.html"); domainUri3 = new Uri("https://www.nhooo.com/index_1.html"); if (domainUri1.Equals(domainUri1) == true) Console.WriteLine("Both are equal"); else Console.WriteLine("Both are not equal"); if (domainUri1.Equals(domainUri2) == true) Console.WriteLine("Both are equal"); else Console.WriteLine("Both are not equal"); if (domainUri1.Equals(domainUri3) == true) Console.WriteLine("Both are equal"); else Console.WriteLine("Both are not equal"); } }
输出结果
Both are equal Both are equal Both are not equal