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


C# Pair.GetHashCode方法代码示例

本文整理汇总了C#中Pair.GetHashCode方法的典型用法代码示例。如果您正苦于以下问题:C# Pair.GetHashCode方法的具体用法?C# Pair.GetHashCode怎么用?C# Pair.GetHashCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Pair的用法示例。


在下文中一共展示了Pair.GetHashCode方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Pair_GetHashCode_Returns_Same_Value_For_Two_Objects_That_Compare_As_Equal

        public void Pair_GetHashCode_Returns_Same_Value_For_Two_Objects_That_Compare_As_Equal()
        {
            var pair1 = new Pair<bool>(false, false);
            var pair2 = new Pair<bool>(false, false);

            Assert.AreEqual(pair1.GetHashCode(), pair2.GetHashCode());
        }
开发者ID:cihanozhan,项目名称:virtual-radar-server,代码行数:7,代码来源:PairTests.cs

示例2: TestGetHashCode

 public void TestGetHashCode()
 {
     Pair<string, string> test = new Pair<string, string>("a", "b");
     Assert.AreEqual(test.GetHashCode(), "a".GetHashCode() ^ "b".GetHashCode());
     Pair<string, string> oneNull = new Pair<string, string>("a", null);
     Assert.AreNotEqual(oneNull.GetHashCode(), "a".GetHashCode());
     Pair<string, string> twoNulls = new Pair<string, string>();
     Assert.AreNotEqual(twoNulls.GetHashCode(), 0);
 }
开发者ID:Joxx0r,项目名称:ATF,代码行数:9,代码来源:TestPair.cs

示例3: GetHashCodeTest

 public void GetHashCodeTest()
 {
     Pair<int> p1 = new Pair<int>();
       Pair<int> p2 = new Pair<int>();
       Assert.AreEqual(p1.GetHashCode(), p2.GetHashCode());
       p1.First = 12;
       Assert.AreNotEqual(p1.GetHashCode(), p2.GetHashCode());
       p2.First = 12;
       Assert.AreEqual(p1.GetHashCode(), p2.GetHashCode());
       p1.Second = 34;
       Assert.AreNotEqual(p1.GetHashCode(), p2.GetHashCode());
       p2.Second = 34;
       Assert.AreEqual(p1.GetHashCode(), p2.GetHashCode());
       p1.First = 13;
       Assert.AreNotEqual(p1.GetHashCode(), p2.GetHashCode());
       p2.First = 13;
       Assert.AreEqual(p1.GetHashCode(), p2.GetHashCode());
       p1.First = p2.Second;
       p1.Second = p2.First;
       Assert.AreEqual(p1.GetHashCode(), p2.GetHashCode());
 }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:21,代码来源:Pair1Test.cs

示例4: GetHashCodeTest

 public void GetHashCodeTest()
 {
     Pair<int, String> p1 = new Pair<int, string>();
       Pair<int, String> p2 = new Pair<int, string>();
       Assert.AreEqual(p1.GetHashCode(), p2.GetHashCode());
       p1.First = 12;
       Assert.AreNotEqual(p1.GetHashCode(), p2.GetHashCode());
       p2.First = 12;
       Assert.AreEqual(p1.GetHashCode(), p2.GetHashCode());
       p1.Second = "Hallo";
       Assert.AreNotEqual(p1.GetHashCode(), p2.GetHashCode());
       p2.Second = "Hallo";
       Assert.AreEqual(p1.GetHashCode(), p2.GetHashCode());
       p1.First = 13;
       Assert.AreNotEqual(p1.GetHashCode(), p2.GetHashCode());
       p2.First = 13;
       Assert.AreEqual(p1.GetHashCode(), p2.GetHashCode());
       p1.Second = "Hallo2";
       Assert.AreNotEqual(p1.GetHashCode(), p2.GetHashCode());
 }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:20,代码来源:Pair2Test.cs

示例5: CanHashCodeTwoNullablePairs

        public void CanHashCodeTwoNullablePairs()
        {
            var pair1 = new Pair<int?>(1, null);
            var pair2 = new Pair<int?>(1, null);
            var pair3 = new Pair<int?>(null, 2);

            pair2.GetHashCode().Should().Be(pair1.GetHashCode());
            pair3.GetHashCode().Should().Not.Be(pair1.GetHashCode());
        }
开发者ID:Trovarius,项目名称:simple,代码行数:9,代码来源:TuplesFixture.cs

示例6: CanHashCodeTwoNullableDifferentTypePairs

        public void CanHashCodeTwoNullableDifferentTypePairs()
        {
            var pair1 = new Pair<string, int?>("1", 2);
            var pair2 = new Pair<string, int?>("1", 2);
            var pair3 = new Pair<string, int?>("1", null);

            pair2.GetHashCode().Should().Be(pair1.GetHashCode());
            pair3.GetHashCode().Should().Not.Be(pair1.GetHashCode());
        }
开发者ID:Trovarius,项目名称:simple,代码行数:9,代码来源:TuplesFixture.cs

示例7: Pair_GetHashCode_Can_Cope_When_Values_Are_Null

        public void Pair_GetHashCode_Can_Cope_When_Values_Are_Null()
        {
            var pair1 = new Pair<string>("A", "B");
            var pair2 = new Pair<string>(null, null);
            var pair3 = new Pair<string>("A", null);
            var pair4 = new Pair<string>(null, "B");
            var pair5 = new Pair<string>("A", "B");

            Assert.AreEqual(pair1.GetHashCode(), pair5.GetHashCode());

            // The others can't be compared for equality because there's no rule to say that if two objects aren't equal
            // then their hashcodes must be different. However it should be able to calculate hashcodes for all of them
            // without any crashes.
            pair2.GetHashCode();
            pair3.GetHashCode();
            pair4.GetHashCode();
        }
开发者ID:cihanozhan,项目名称:virtual-radar-server,代码行数:17,代码来源:PairTests.cs


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