本文整理汇总了C#中System.Tuple<T1,T2,T3,T4,T5>.IStructuralEquatable.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# Tuple<T1,T2,T3,T4,T5>.IStructuralEquatable.Equals方法的具体用法?C# Tuple<T1,T2,T3,T4,T5>.IStructuralEquatable.Equals怎么用?C# Tuple<T1,T2,T3,T4,T5>.IStructuralEquatable.Equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Tuple<T1,T2,T3,T4,T5>
的用法示例。
在下文中一共展示了Tuple<T1,T2,T3,T4,T5>.IStructuralEquatable.Equals方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoubleComparer
//引入命名空间
using System;
using System.Collections;
public class DoubleComparer<T1, T2, T3, T4, T5> : IEqualityComparer
{
private double difference;
private int argument = 0;
public DoubleComparer(double difference)
{
this.difference = difference;
}
new public bool Equals(object x, object y)
{
argument += 1;
// Return true for Item1.
if (argument == 1) return true;
double d1 = (double) x;
double d2 = (double) y;
if (d1 - d2 < d1 * difference)
return true;
else
return false;
}
public int GetHashCode(object obj)
{
if (obj is T1)
return ((T1) obj).GetHashCode();
else if (obj is T2)
return ((T2) obj).GetHashCode();
else if (obj is T3)
return ((T3) obj).GetHashCode();
else if (obj is T4)
return ((T4) obj).GetHashCode();
else
return ((T5) obj).GetHashCode();
}
}
public class Example
{
public static void Main()
{
var value1 = GetValues(1);
var value2 = GetValues(2);
IStructuralEquatable iValue1 = value1;
Console.WriteLine("{0} =\n{1} :\n{2}", value1, value2,
iValue1.Equals(value2,
new DoubleComparer<int, double, double, double, double>(.01)));
}
private static Tuple<int, double, double, double, double> GetValues(int ctr)
{
// Generate four random numbers between 0 and 1
Random rnd = new Random((int)DateTime.Now.Ticks >> 32 >> ctr);
return Tuple.Create(ctr, rnd.NextDouble(), rnd.NextDouble(),
rnd.NextDouble(), rnd.NextDouble());
}
}