本文整理汇总了C#中System.Collections.IStructuralEquatable接口的典型用法代码示例。如果您正苦于以下问题:C# IStructuralEquatable接口的具体用法?C# IStructuralEquatable怎么用?C# IStructuralEquatable使用的例子?那么恭喜您, 这里精选的接口代码示例或许可以为您提供帮助。
IStructuralEquatable接口属于System.Collections命名空间,在下文中一共展示了IStructuralEquatable接口的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Equals
//引入命名空间
using System;
using System.Collections;
using System.Collections.Generic;
public class NanComparer : IEqualityComparer
{
public new bool Equals(object x, object y)
{
if (x is float)
return (float) x == (float) y;
else if (x is double)
return (double) x == (double) y;
else
return EqualityComparer<object>.Default.Equals(x, y);
}
public int GetHashCode(object obj)
{
return EqualityComparer<object>.Default.GetHashCode(obj);
}
}
示例2: Main
public class Example
{
public static void Main()
{
var t1 = Tuple.Create(12.3, Double.NaN, 16.4);
var t2 = Tuple.Create(12.3, Double.NaN, 16.4);
// Call default Equals method.
Console.WriteLine(t1.Equals(t2));
IStructuralEquatable equ = t1;
// Call IStructuralEquatable.Equals using default comparer.
Console.WriteLine(equ.Equals(t2, EqualityComparer<object>.Default));
// Call IStructuralEquatable.Equals using
// StructuralComparisons.StructuralEqualityComparer.
Console.WriteLine(equ.Equals(t2,
StructuralComparisons.StructuralEqualityComparer));
// Call IStructuralEquatable.Equals using custom comparer.
Console.WriteLine(equ.Equals(t2, new NanComparer()));
}
}
输出:
True True True False