本文整理匯總了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());
}
}