Есть ли простой способ сделать структуру шаблонной и не потерять работоспособность перегрузок? - C#
Формулировка задачи:
Всем привет. Скажите, пожалуйста, есть ли в C# простой способ сделать структуру шаблонной и не потерять работоспособность перегрузок?:
struct DoubleUInt32Key
{
private uint Key1;
private uint Key2;
public DoubleUInt32Key(uint Key1, uint Key2)
{
this.Key1 = Key1;
this.Key2 = Key2;
}
public static bool operator ==(DoubleUInt32Key a, DoubleUInt32Key b)
{
if (a.Key1 == b.Key1 && a.Key2 == b.Key2)
return true;
else return false;
}
public static bool operator !=(DoubleUInt32Key a, DoubleUInt32Key b)
{
if (a.Key1 != b.Key1 && a.Key2 != b.Key2)
return true;
else return false;
}
}Решение задачи: «Есть ли простой способ сделать структуру шаблонной и не потерять работоспособность перегрузок?»
textual
Листинг программы
struct DoubleKey<T>
{
private T Key1;
private T Key2;
public DoubleKey(T Key1, T Key2)
{
this.Key1 = Key1;
this.Key2 = Key2;
}
public static bool operator ==(DoubleKey<T> a, DoubleKey<T> b)
{
if (a.Key1.Equals(b.Key1) && a.Key2.Equals(b.Key2))
return true;
else return false;
}
public static bool operator !=(DoubleKey<T> a, DoubleKey<T> b)
{
return !(a == b);
}
}