what is the best way to have a Generic Comparer
Posted
by oo
on Stack Overflow
See other posts from Stack Overflow
or by oo
Published on 2010-04-01T03:02:03Z
Indexed on
2010/04/01
3:13 UTC
Read the original article
Hit count: 249
I have a lot of comparer classes where the class being compared is simply checking the name property of the object and doing a string compare. For example:
public class ExerciseSorter : IComparer<Exercise>
{
public int Compare(Exercise x, Exercise y)
{
return String.Compare(x.Name, y.Name);
}
}
public class CarSorter : IComparer<Car>
{
public int Compare(Car x, Car y)
{
return String.Compare(x.Name, y.Name);
}
}
what is the best way to have this code generic so i dont need to write redundant code over and over again.
© Stack Overflow or respective owner