C# - How to implement multiple comparers for an IComparable class?

后端 未结 4 1383
时光取名叫无心
时光取名叫无心 2020-12-30 08:22

I have a class that implements IComparable.

public class MyClass : IComparable
{
    public int CompareTo(MyClass c)
    {
        return this         


        
4条回答
  •  庸人自扰
    2020-12-30 08:32

    If you have multiple ways to sort a list of your objects, you obviously have to specify which option to choose. That's what the other overrides of Sort are good for. Have a look at IComparer and Comparison.

提交回复
热议问题