Uri.Equals(Object)方法用於比較兩個Uri實例是否相等。
用法:
public override bool Equals (object comparand);
Here, it takes the Uri instance or a URI identifier to compare with the current instance.
返回值:如果兩個實例表示相同的URI,則此方法返回布爾值true,否則返回false。
以下示例程序旨在說明Uri.Equals(Object)方法的用法:
示例1:
// C# program to demonstrate the
// Uri.Equals(Object) Method
using System;
using System.Globalization;
class GFG {
// Main Method
public static void Main()
{
// Declaring and initializing address1
Uri address1 = new Uri("http://www.contoso.com/index.htm#search");
// Declaring and intializing address2
Uri address2 = new Uri("http://www.contoso.com/index.htm");
// Comparing both instance
// using CheckHostName() method
bool value = address1.Equals(address2);
// Displaying the result
if (value)
Console.WriteLine("address1 is Equals to address2");
else
Console.WriteLine("address1 is not Equals to address2");
}
}
輸出:
address1 is Equals to address2
示例2:
// C# program to demonstrate the
// Uri.Equals(Object) Method
using System;
using System.Globalization;
class GFG {
// Main Method
public static void Main()
{
// calling get() method
get(new Uri("http://www.contoso.com"),
new Uri("http://www.contoso.com"));
get(new Uri("http://www.google.com"),
new Uri("http://www.facebook.com"));
}
// defining get() method
public static void get(Uri address1,
Uri address2)
{
// Comparing both instance
// using CheckHostName() method
bool value = address1.Equals(address2);
// Displaying the result
if (value)
Console.WriteLine("{0} is Equals to {1}", address1, address2);
else
Console.WriteLine("{0} is not Equals to {1}", address1, address2);
}
}
輸出:
http://www.contoso.com/ is Equals to http://www.contoso.com/ http://www.google.com/ is not Equals to http://www.facebook.com/
參考:
相關用法
- C# DateTimeOffset.Add()用法及代碼示例
- C# String.Contains()用法及代碼示例
- C# Math.Sin()用法及代碼示例
- C# Math.Cos()用法及代碼示例
- C# Dictionary.Add()用法及代碼示例
- C# Math.Tan()用法及代碼示例
- C# Math.Abs()方法用法及代碼示例
- C# Math.Exp()用法及代碼示例
- C# Math.Abs()函數用法及代碼示例
注:本文由純淨天空篩選整理自RohitPrasad3大神的英文原創作品 C# | Uri.Equals(Object) Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。