本文整理汇总了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());
}
示例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);
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}
示例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();
}