当前位置: 首页>>代码示例>>C#>>正文


C# Uri.GetHashCode方法代码示例

本文整理汇总了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);
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:41,代码来源:UriTests.cs

示例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);
     }
 }
开发者ID:SGuyGe,项目名称:corefx,代码行数:17,代码来源:Uri.MethodsTests.cs


注:本文中的Uri.GetHashCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。