本文整理汇总了C#中Uri.GetHashCode方法的典型用法代码示例。如果您正苦于以下问题:C# Uri.GetHashCode方法的具体用法?C# Uri.GetHashCode怎么用?C# Uri.GetHashCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Uri
的用法示例。
在下文中一共展示了Uri.GetHashCode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestCompare
public static void TestCompare()
{
Uri uri1 = new Uri("http://www.contoso.com/path?name#frag");
Uri uri2 = new Uri("http://www.contosooo.com/path?name#slag");
Uri uri2a = new Uri("http://www.contosooo.com/path?name#slag");
int i;
i = Uri.Compare(uri1, uri2, UriComponents.AbsoluteUri, UriFormat.UriEscaped, StringComparison.CurrentCulture);
Assert.Equal(i, -1);
i = Uri.Compare(uri1, uri2, UriComponents.Query, UriFormat.UriEscaped, StringComparison.CurrentCulture);
Assert.Equal(i, 0);
i = Uri.Compare(uri1, uri2, UriComponents.Query | UriComponents.Fragment, UriFormat.UriEscaped, StringComparison.CurrentCulture);
Assert.Equal(i, -1);
bool b;
b = uri1.Equals(uri2);
Assert.False(b);
b = uri1 == uri2;
Assert.False(b);
b = uri1 != uri2;
Assert.True(b);
b = uri2.Equals(uri2a);
Assert.True(b);
b = uri2 == uri2a;
Assert.True(b);
b = uri2 != uri2a;
Assert.False(b);
int h2 = uri2.GetHashCode();
int h2a = uri2a.GetHashCode();
Assert.Equal(h2, h2a);
}
示例2: Equals
public void Equals(Uri uri1, object obj, bool expected)
{
Uri uri2 = obj as Uri;
if (uri1 != null)
{
Assert.Equal(expected, uri1.Equals(obj));
if (uri2 != null)
{
Assert.Equal(expected, uri1.GetHashCode().Equals(uri2.GetHashCode()));
}
}
if (!(obj is string))
{
Assert.Equal(expected, uri1 == uri2);
Assert.Equal(!expected, uri1 != uri2);
}
}