I have 2 key value comparers - in both I am using key to compare, which is string. Can I use generic for the value - so instead of have 2 classes I can have only 1?
So instead of the classes below I wish I could have only 1 class
class KvpComparer : IEqualityComparer < KeyValuePair < string, T>>
{
...
}
class KvpComparer : IEqualityComparer<KeyValuePair<string, Tuple<string, string>>>
{
public bool Equals(KeyValuePair<string, Tuple<string, string>> x, KeyValuePair<string, Tuple<string, string>> y)
{
return x.Key.Equals(y.Key);
}
public int GetHashCode(KeyValuePair<string, Tuple<string, string>> obj)
{
return obj.Key.GetHashCode();
}
}
class KvpComparer2 : IEqualityComparer<KeyValuePair<string, string>>
{
public bool Equals(KeyValuePair<string, string> x, KeyValuePair<string, string> y)
{
return x.Key.Equals(y.Key);
}
public int GetHashCode(KeyValuePair<string, string> obj)
{
return obj.Key.GetHashCode();
}
}