Shortest code to calculate list min/max in .NET

后端 未结 4 1989
旧时难觅i
旧时难觅i 2020-12-10 04:45

I\'d like something like

int minIndex = list.FindMin(delegate (MyClass a, MyClass b) {returns a.CompareTo(b);});

Is there a builtin way to

4条回答
  •  难免孤独
    2020-12-10 05:13

    Try looking at these:

    Min

    Max

    As long as your class implements IComparable, all you have to do is:

    List list = new List();
    //add whatever you need to add
    
    MyClass min = list.Min();
    MyClass max = list.Max();
    

提交回复
热议问题