-1
我有一個類,看起來像這樣使類它自己的Comparer
public class Foo
{
public int A { get; set; }
public List<string> Bs { get; set; }
}
而一個比較器,看起來像這樣
public class FooComparer : IComparer<Foo>
{
public int Compare(Foo x, Foo y)
{
return x.A.CompareTo(y.A);
}
}
我想這些組合成一兩件事,但是很關心這不是很好的做法,或者只是顯得很古怪。你對此有什麼看法
public class Foo : IComparer<Foo>
{
public int A { get; set; }
public List<string> Bs { get; set; }
public int Compare(Foo x, Foo y)
{
return x.A.CompareTo(y.A);
}
}
您通常直接實現'IComparable的' –
xanatos
@AdamHouldsworth實施例的代碼是[題外話](http://codereview.stackexchange.com/幫助/話題)進行代碼審查。 – Mast
@Mast啊,因爲這是一般的最佳做法?是啊,夠公平的,但仍然自以爲是。只是不想在沒有提供替代品的情況下投票結束。 –