本文整理汇总了C#中IEqualityComparer.GetHashCode方法的典型用法代码示例。如果您正苦于以下问题:C# IEqualityComparer.GetHashCode方法的具体用法?C# IEqualityComparer.GetHashCode怎么用?C# IEqualityComparer.GetHashCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEqualityComparer
的用法示例。
在下文中一共展示了IEqualityComparer.GetHashCode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AssertCompareEqual
static void AssertCompareEqual(IEqualityComparer<NameAndNumber> comparer, NameAndNumber x, NameAndNumber y)
{
Assert.IsTrue(comparer.Equals(x, y));
Assert.IsTrue(comparer.Equals(y, x));
if (x != null && y != null)
{
Assert.AreEqual(comparer.GetHashCode(x), comparer.GetHashCode(y));
}
}
示例2:
int IStructuralEquatable.GetHashCode(IEqualityComparer comparer) {
object obj;
if (TryGetObject(out obj)) {
return comparer.GetHashCode(obj);
}
return comparer.GetHashCode(null);
}
示例3: GetHashCode
public int GetHashCode(IEqualityComparer comparer)
{
return comparer.GetHashCode(this);
}
示例4: TestComparisons
/// <summary>
/// Utility method to perform appropriate comparisons with the given comparer.
/// For all tests:
/// A10 == A10
/// B15 == B15
/// A10 != B15
/// A10 != null
/// B15 != null
/// A10 might equal B10, and A10 might equal A15, depending on the comparer -
/// this is in each individual test.
/// </summary>
static void TestComparisons(IEqualityComparer<NameAndNumber> comparer)
{
AssertCompareEqual(comparer, A10, A10);
AssertCompareEqual(comparer, B15, B15);
AssertCompareEqual(comparer, null, null);
AssertCompareNotEqual(comparer, A10, B15);
AssertCompareNotEqual(comparer, A10, null);
AssertCompareNotEqual(comparer, B15, null);
AssertCompareNotEqual(comparer, null, B15);
AssertCompareNotEqual(comparer, null, A10);
try
{
comparer.GetHashCode(null);
}
catch (ArgumentNullException)
{
// Expected
}
}